栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch curl命令:http请求

elasticsearch curl命令:http请求

部分来源《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

返回结果说明

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/612379.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号