The text is concise version using marvel operation
Plug-in installation tutorial marvel
https://blog.csdn.net/u013294097/article/details/100144725
You can do the initial operation of the index 1. Before creating the index,
For example, specify the number of shards, and the number of replicas
The correct syntax:
CURL -XPUT 'http://ip:port/library/' -d '{
"settings":{
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}'
Use marvel tool syntax
#---------------------------------
#初始化初始化索引
#创建索引之前可以对索引做初始化操作,比如指定shards数量以及replicas的数量
PUT http://localhost:9200/lilbrary/
{
"settings":{
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
The above can be replaced by other number_of_replicas
blocks_read_only set to true, then the current index only allowed to read, write or update is not allowed
blocks_read set to true, disables reads
blocks_write set to true, the write operation is prohibited
blocks_metadata set to true, the prohibition of metadata operation
2. You can get detailed configuration information indexed by GET
GET /lilbrary/_settings
If the two indexes
GET /library1,library2/_settings
Get all the index information
GET /_all/_settings
More complete statement:
CURL -XGET 'http://ip:port/library/_settings'
CURL -XGET 'http://ip:port/library,library2/_settings'
CURL -XGET 'http://ip:port/_all/_settings'
3.API create, update, delete indexes
3.1 How to create an index with the API
例:curl -XPUT 'http://ip:port/twitter/tweet/1' -d '{"user":"kimchv","post_date":"2019-08-29T14:12:12","message":"trying out Elasticsearch"}'
Marvel of use cases:
Bring the new ID
PUT lilbrary/books/1
{
"title":"Elasticsearch: The Definitive Guide",
"name":{
"first":"Zachary",
"last":"Tong"
},
"publicsh_date":"2019-08-29",
"price":"49.99"
}
POST without the ID (you can update, add, update, when the tape id)
POST /library/books/
{
"title":"Elasticsearch : blueprints",
"name":{
"first":"Vineeth",
"last":"Monan"
},
"publish_date":"2015-06-06",
"price":"35.99"
}
How to update the index 3.2 API
例如:curl -XPOST 'http://ip:port/test/type1/1/_update' -d '{"script":"ctx._source.conter+=count","params":{"count":4}}'
Case Case with POST above, the above method is not recommended
Case 2:
通过 _update API的方式单独更新想要更新的
POST /library/books/1/_update
{
"doc":{
"price":"59.9"
}
}
How to delete the index by 3.3 API
例:curl -XDELETE 'http://ip:port/twitter/tweet/1'
marvel Case:
DELETE /library/books/1
You can delete a TYPE
DELETE /library/books
Delete the entire index
DELETE /library
How to query Index 3.4
marvel way:
GET /library/books/1
Gets the specified field by _source, multi-field, or all of the information
GET /library/books/1?_source=title
GET /library/books/1?_source=title,price
GET /library/books/1?_source
4. batch query
4.1 general inquiry:
curl 'localhost:9200/_mget' -d{
"docs":[
{
"_index":"library",
"_type":"books",
"_id":1,
"_source":["keyword","keyword2"]
},
{
"_index":"library",
"_type":"books",
"_id":8,
"_source":"keyword"
}
,
{
"_index":"library",
"_type":"books",
"_id":10,
"_source":"keyword"
}
]
}
marvel query:
GET /_mget
{
"docs":[
{
"_index":"library",
"_type":"books",
"_id":1,
"_source":["keyword","keyword2"]
},
{
"_index":"library",
"_type":"books",
"_id":8,
"_source":"keyword"
}
,
{
"_index":"library",
"_type":"books",
"_id":10,
"_source":"keyword"
}
]
}
4.2 batch query _mget get a different ID documents of the same type under the same index
Normal mode:
方式1:
curl 'localhost:9200/library/books/_mget' -d
{
"docs":[
{"_id":6},
{"_id":28}
]
}
方式2:
curl 'localhost:9200/library/books/_mget' -d
{
"ids":["6","28"]
}
marvel way:
方式1:
GET /library/books/_mget
{
"docs":[
{"_id":6},
{"_id":28}
]
}
方式2:
GET /library/books/_mget
{
"ids":["6","28"]
}
The batch operation _bulk
In order to achieve create multiple documents, index, update, delete and use
The request body bulk format (landscaping not shown):
There are four action: create, index, update, delete
create: create it when a document does not exist.
index: create a new document or replace an existing document.
update: partial update the document.
delete: delete a document
{action:{metadata}}\n
{request body}\n
{action:{metadata}}\n
{request body}\n
...
例如:{"delete":{"_index":"library","_type":"books","_id":"1"}}
Example 1 (marvel mode):
POST /library/books/_bulk
{"index":{"_id":1}}
{"title":"Elasticsearch: The Definitive Guide","price":5}
{"index":{"_id":2}}
{"title":"The Elasticsearch cookbook","price":15}
{"index":{"_id":3}}
{"title":"Elasticsearch Blueprints","price":9}
{"index":{"_id":4}}
{"title":"Think in Python","price":22}
{"index":{"_id":5}}
{"title":"Thinking in Java","price":7}
Example 2 (marvel embodiment)
Next is the use of update, delete operation example
POST /library/books/_bulk
{"delete":{"_index":"library","_type":"books","_id":"1"}}
{"create":{"_index":"music","_type":"classical","_id":"1"}}
{"title":"Ave Verum Corpus"}
{"index":{"_index":"music","_type":"classical"}}
{"title":"Litaniac de Venerabili Altaris Sacromento"}
{"update":{"_index":"library","_type":"books","_id":"2"}}
{"doc":{"price":"18"}}
5.2 bulk optimal value processing document size
Go to the actual testing environment, different hardware, different performance