索引相关

  1. #查看索引相关信息
  2. GET {index_name}
  3. #查看索引总数
  4. GET {index_name}/_count
  5. #查看前10条文档,了解文档格式
  6. POST {index_name}/_search
  7. {
  8. }
  9. #查看indices
  10. GET /{index_name}/indices/kibana*?v&s=index
  11. #查看状态为绿的索引
  12. GET /{index_name}/indices?v&health=green
  13. #按照文档个数排序
  14. GET /{index_name}/indices?v&s=docs.count:desc
  15. #查看具体的字段
  16. GET /{index_name}/indices/kibana*?pri&v&h=health,index,pri,rep,docs.count,mt

创建文档

  1. POST {index_name}/_create/1
  2. {
  3. "field": "value"
  4. }
  1. POST {index_name}/_doc
  2. {
  3. "field": "value"
  4. }
  1. POST {index_name}/_doc/1
  2. {
  3. "field": "value"
  4. }
  1. POST {index_name}/_doc/1?op_type=create
  2. {
  3. "field": "value"
  4. }

更新文档

  1. POST {index_name}/_update/1
  2. {
  3. "doc": {
  4. "field": "value"
  5. }
  6. }

删除文档

  1. DELETE {index_name}/_doc/1

查询文档

  1. GET {index_name}/_doc/1
  1. POST {index_name}/_search
  2. {
  3. }

BULK 批量操作

  1. POST _bulk
  2. { "index" : { "_index" : "{index_name}", "_id" : "1" } }
  3. { "field1" : "value1" }
  4. { "delete" : { "_index" : "{index_name}", "_id" : "2" } }
  5. { "create" : { "_index" : "{index_name}", "_id" : "3" } }
  6. { "field1" : "value3" }
  7. { "update" : {"_index" : "{index_name}", "_id" : "1"} }
  8. { "doc" : {"field2" : "value2"} }
  1. GET /_mget
  2. {
  3. "docs" : [
  4. {
  5. "_index" : "{index_name}",
  6. "_id" : "1"
  7. },
  8. {
  9. "_index" : "{index_name}",
  10. "_id" : "2"
  11. }
  12. ]
  13. }

并发控制

Elasticsearch 采用的是乐观并发控制。假定冲突是不会发生的,不会阻塞正在尝试的操作,如果数据在读写中被修改,更新将会失败。应用程序决定如何解决冲突,例如重试更新,使用新的数据,或者将错误报告给用户。
Elasticsearch 中的文档是不可变更的,如果你更新一个文档,该文档的版本号加一。

  1. # products:索引名称
  2. DELETE products
  3. PUT products
  4. PUT products/_doc/1
  5. {
  6. "title":"iphone",
  7. "count":100
  8. }
  1. GET products/_doc/1
  2. PUT products/_doc/1?if_seq_no=1&if_primary_term=1
  3. {
  4. "title":"iphone",
  5. "count":100
  6. }

image.png

  1. PUT products/_doc/1?version=30000&version_type=external
  2. {
  3. "title":"iphone",
  4. "count":100
  5. }