部分来源《es实战》
部分HTTP请求获取分片信息
curl localhost:9200/_cat/shards?v
index shard prirep state docs store ip node
.kibana_task_manager_7.14.2_001 0 p STARTED 14 42.7mb 172.17.0.3 83a096a93868
book 0 p STARTED 3 5.4kb 172.17.0.3 83a096a93868
book 0 r UNASSIGNED
创建文档
curl -H "Content-Type: application/json"
> -X PUT localhost:9200/book/group/1?pretty
> -d '{"name": "es in action","organizer": "bob"}'
{
"_index" : "book",
"_type" : "group",
"_id" : "1",
"_version" : 5,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
添加多个文档备用
curl -H "Content-Type: application/json" -X PUT localhost:9200/book/group/2?pretty -d '{"name": "es study","organizer": "andy"}'
curl -H "Content-Type: application/json" -X PUT localhost:9200/book/group/3?pretty -d '{"name": "java study a test","organizer": "andy","ext":"only 3 have it"}'
获取文档
curl localhost:9200/book/group/1?pretty
{
"_index" : "book",
"_type" : "group",
"_id" : "1",
"_version" : 5,
"_seq_no" : 4,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "es in action",
"organizer" : "bob"
}
}
获取映射
curl localhost:9200/book/_mapping?pretty
{
"book" : {
"mappings" : {
"properties" : {
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"organizer" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
搜索
[root@localhost ~]# curl localhost:9200/book/group/_search?q=es&size=1
[1] 85817
[root@localhost ~]# {"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":0.5442147,"hits":[{"_index":"book","_type":"group","_id":"2","_score":0.5442147,"_source":{"name": "es study","organizer": "andy"}},{"_index":"book","_type":"group","_id":"1","_score":0.4700036,"_source":{"name": "es in action","organizer": "bob"}}]}}
[1]+ 完成 curl localhost:9200/book/group/_search?q=es
搜索返回部分字段
curl localhost:9200/book/_search?pretty&q=es&fields=name,ext&size=1
在部分字段中搜索
curl localhost:9200/book/_search?pretty&q=name:es&size=1
多个索引中搜索
curl localhost:9200/book,otherIndex/_search?pretty&q=es
全部索引中查找:不推荐
curl localhost:9200/_search?pretty&q=es
也可使用json指定搜索条件,实现一些更加复杂的查询
curl localhost:9200/book/_search
> -d '{"query":{"query_string":{"query":"es"}}}'
> -H "Content-Type: application/json"
更新文档
curl -XPOST localhost:9200/book/group/1/_update -d '{"doc": {"ext": "update add ext"}}' -H "Content-Type: application/json"
关闭/打开索引
curl -XPOST localhost:9200/book/_close
curl -XPOST localhost:9200/book/_open
返回结果说明



