当前位置:网站首页>Elasitcsearch basic learning notes (1)

Elasitcsearch basic learning notes (1)

2022-06-11 16:40:00 chenxiky

One . Basic concepts

Classification of data

        1. Structured data : Having a fixed or limited format ⻓ Degree data , Such as a database , Metadata, etc . For structured data , We ⼀ Generally, you can use relational database (mysql,oracle etc. ) Of table Of ⽅ Storage and search , You can also build ⽴ Indexes . adopt b-tree And other data structures to quickly search data .

        2.⾮ Structured data : whole ⽂ data , I don't know ⻓ or ⽆ Fixed format data , Like email ,word⽂ Gear, etc . about ⾮ Structured data , That is, to all ⽂ There are two main types of data search ⽅ Law : Sequential scanning , whole ⽂ Search .

whole ⽂ Search for

Yes ⾮ Information is extracted from structured data , Reorganize , Make it ⼀ Structure , And then there are ⼀ Structured data entry ⾏ Search for , from ⽽ Achieve a relatively fast search ⽬ Of . this Kind of ⽅ The formula constitutes the whole ⽂ The basic idea of search . This part starts from ⾮ A letter extracted from structured data and then reorganized Rest , We call it index .

What is all ⽂ Search engine ?

⼯ How it works : It's a computer cable Introduce the program through scanning ⽂ Every... In the chapter ⼀ Word , For each ⼀ Geci Jian ⽴⼀ An index , Indicate that the word is in ⽂ The number of occurrences and bits in the chapter Set up , When ⽤ When the user inquires , The search program is built in advance ⽴ The introduction of ⾏ lookup , And feed back the search results to ⽤ Household .

The main search engines are :Lucene 、Solr 、Elastic search.

Suitable for all ⽂ The scenario of the index engine

The data objects searched are ⼤ Quantitative ⾮ A structured ⽂ This data .

⽂ The amount of this data reaches ⼗ Tens of thousands or millions , what ⾄ more .

⽀ a ⼤ Volume is based on interactive ⽂ This query . demand ⾮ Always flexible ⽂ Search for .

For security affairs ,⾮⽂ The demand for this data operation is relatively small .

Elasticsearch Elasticsearch yes ⼀ Open source , yes ⼀ Based on Apache Lucene Library built Restful Search engine .

The main function : Distributed search Data analysis Group and aggregate

Should be ⽤ scene : Wikipedia Stack Overflow GitHub Online retailers ⽹ standing ⽇ Log data analysis Commodity price monitoring ⽹ standing BI System On-site search Basketball Forum

Two .Elasticsearch Introduction to the basic catalogue and its general structure

Indexes (index):⼀ An index can be understood as ⼀ A relational database .

  type (type): ⼀ Kind of type It's like ⼀ Class table ,⽐ Such as user surface ,order surface . Be careful : ES 5.x in ⼀ individual index There can be many type. ES 6.x in ⼀ individual index There can only be ⼀ Kind of type. ES 7.x Has been removed since type The concept .

mapping (mapping) :mapping Defines the type of each field and other information . It is equivalent to the table structure in relational database . ⽂ files (document) ⼀ individual document Equivalent to... In a relational database ⼀⾏ Record .

Field (field) : It is equivalent to the fields of relational database tables colony (cluster) Clusters are composed of ⼀ One or more nodes ,⼀ Clusters have ⼀ Default names "elasticsearch".

node (node) : Cluster node ,⼀ A machine or ⼀ A process .

branch ⽚ And copies (shard) : The copy is divided into ⽚ Copy of . branch ⽚ There are principal components ⽚(primary Shard) And copies ⽚(replica Shard) Points . ⼀ individual Index Data is physically distributed across multiple primary partitions ⽚ in , Each main branch ⽚ Only part of the data is stored . Each main branch ⽚ There can be multiple copies , Let's divide the copies ⽚, It is the main part ⽚ Copy .

        elasticsearch send ⽤RESTful⻛ grid api To design the :RESTful yes ⼀ Specifications and constraints of the architecture 、 principle , The architecture that fits this specification is RESTful framework .

  3、 ... and .ES Basic use

1. The introduction of the index and its application ⽤

Add index :PUT "localhost:9200/nba"

Get index :GET "localhost:9200/nba"

Delete index :DELETE "localhost:9200/nba"

Get index in batch :GET "localhost:9200/nba,cba"

Get all indexes :GET "localhost:9200/_all"   GET "localhost:9200/_cat/indices?v"

2. Introduction and implementation of mapping ⽤

New mapping PUT "localhost:9200/nba/_mapping"

{ "properties": { "name": { "type": "text" }, "team_name": { "type": "text" }, "position": { "type": "keyword" }, "play_year": { "type": "keyword" }, "jerse_no": { "type": "keyword"  Respond to   obtain   request   Respond to   Batch acquisition   request  } } }

Acquisition mapping  GET "localhost:9200/xdclass/_mapping"

Batch acquisition :GET "localhost:9200/nba,cba/mapping"

Get all :1.X GET "localhost:9200/_mapping";2.GET "localhost:9200/_all/_mapping"

Modify mapping :PUT "localhost:9200/nba/_mapping"

{
 "properties": {
 "name": {
 "type": "text"
 },
 "team_name": {
 "type": "text"
 },
 "position": {
 "type": "keyword"
 },
 "play_year": {
 "type": "keyword"
 },
 "jerse_no": {
 "type": "keyword"
 },
 "country": {
 "type": "keyword"
 }
 }
}

3.⽂ Addition, deletion and modification of files

newly added ⽂ files :1.PUT localhost:9200/nba/_doc/1 ( Appoint id) notes : Specify the need for PUT

                  2.POST localhost:9200/nba/_doc ( Don't specify id)  You don't have to specify

{ "name":" library ⾥", "team_name":" yong ⼠", "position":" Organizing guards ", "play_year":"10", "jerse_no":"30" }

see ⽂ files :GET localhost:9200/nba/_doc/1

View multiple ⽂ files :1.POST localhost:9200/_mget

{"docs" : [ { "_index" : "nba", "_type" : "_doc", "_id" : "1" }, { "_index" : "nba", "_type" : "_doc", "_id" : "2" } ] }

2.POST localhost:9200/nba/doc/mget

{ "docs" : [ { "_id" : "1" }, { "_id" : "2" } ] }

3.GET localhost:9200/nba/doc/mget

{ "ids" : ["1", "2"] }

modify ⽂ files : POST localhost:9200/nba/_update/1

{ "doc": { "name": " harden ", "team_name": "⽕ arrow ", "position": " Double energy guard ", "play_year": "10", "jerse_no": "13" } }

towards _source Field , increase ⼀ A field :POST localhost:9200/nba/_update/1

{ "script": "ctx._source.age = 18" }

from _source Field , Delete ⼀ A field :POST localhost:9200/nba/_update/1

{ "script": "ctx._source.remove(\"age\")" }

According to the parameter value , Updates the specified ⽂ File fields :POST localhost:9200/nba/_update/1

{ "script": { "source": "ctx._source.age += params.age", "params": { "age": 4 } } }

upsert When the specified ⽂ When the gear does not exist ,upsert The content contained in the parameter will be inserted ⼊ Into the index , As ⼀ individual new ⽂ files ; If specified ⽂ The file does not exist ,ElasticSearch The engine will run ⾏ Specified update logic .

POST localhost:9200/nba/_update/3

{ "script": { "source": "ctx._source.allstar += params.allstar", "params": { "allstar": 4 } }, "upsert": { "allstar": 1 } }

Delete ⽂ files :DELETE localhost:9200/nba/_doc/1

To be continued ......

 

原网站

版权声明
本文为[chenxiky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111634262205.html

随机推荐