elasticsearch curl命令:http请求

部分HTTP请求

创建文档,没有索引、类型会自动创建
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/group/_search?q=es&fields=name,ext&size=1

在部分字段中搜索
curl localhost:9200/book/group/_search?q=name:es&size=1

多个索引中搜索
curl localhost:9200/book,otherIndex/group/_search?q=es




Guess you like

Origin blog.csdn.net/machao0_0/article/details/121583106