索引相关
#查看索引相关信息
GET {index_name}
#查看索引总数
GET {index_name}/_count
#查看前10条文档,了解文档格式
POST {index_name}/_search
{
}
#查看indices
GET /{index_name}/indices/kibana*?v&s=index
#查看状态为绿的索引
GET /{index_name}/indices?v&health=green
#按照文档个数排序
GET /{index_name}/indices?v&s=docs.count:desc
#查看具体的字段
GET /{index_name}/indices/kibana*?pri&v&h=health,index,pri,rep,docs.count,mt
创建文档
POST {index_name}/_create/1
{
"field": "value"
}
POST {index_name}/_doc
{
"field": "value"
}
POST {index_name}/_doc/1
{
"field": "value"
}
POST {index_name}/_doc/1?op_type=create
{
"field": "value"
}
更新文档
POST {index_name}/_update/1
{
"doc": {
"field": "value"
}
}
删除文档
DELETE {index_name}/_doc/1
查询文档
GET {index_name}/_doc/1
POST {index_name}/_search
{
}
BULK 批量操作
POST _bulk
{ "index" : { "_index" : "{index_name}", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "{index_name}", "_id" : "2" } }
{ "create" : { "_index" : "{index_name}", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_index" : "{index_name}", "_id" : "1"} }
{ "doc" : {"field2" : "value2"} }
GET /_mget
{
"docs" : [
{
"_index" : "{index_name}",
"_id" : "1"
},
{
"_index" : "{index_name}",
"_id" : "2"
}
]
}
并发控制
Elasticsearch 采用的是乐观并发控制。假定冲突是不会发生的,不会阻塞正在尝试的操作,如果数据在读写中被修改,更新将会失败。应用程序决定如何解决冲突,例如重试更新,使用新的数据,或者将错误报告给用户。
Elasticsearch 中的文档是不可变更的,如果你更新一个文档,该文档的版本号加一。
# products:索引名称
DELETE products
PUT products
PUT products/_doc/1
{
"title":"iphone",
"count":100
}
GET products/_doc/1
PUT products/_doc/1?if_seq_no=1&if_primary_term=1
{
"title":"iphone",
"count":100
}
PUT products/_doc/1?version=30000&version_type=external
{
"title":"iphone",
"count":100
}