天天看点

es - elasticsearch mapping - meta fields - 3

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问 :_id有什么特点?

答 :

es - elasticsearch mapping - meta fields - 3

问 :_id如何使用?

答 :

# _id
# 索引
POST /id_test/_doc/1
{
  "name" : "hellogood"
}

# 索引
POST /id_test/_doc/2
{
  "name" : "me"
}

# 索引
POST /id_test/_doc
{
  "name" : "tea"
}

# 搜索
GET /id_test/_search
{
  "query" : {
    "terms" : {
      "_id" : [1, 2]
    }
  }
}

# 结果
{
  "took" : 729,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "id_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "hellogood"
        }
      },
      {
        "_index" : "id_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "me"
        }
      }
    ]
  }
}

           

继续阅读