_id field

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-id-field.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/_id+field

贡献者 : 朱彦安ApacheCNApache中文网

每个索引的文档都与一个 _type (请参见“Mapping Types”)和一个 _id 相关联。

_id字段不被索引,因为它的值可以从 _uid 字段自动导出。

_id字段的值可以在某些查询( term , terms , match , query_string , simple_query_string )中访问,但不能在 aggregations(聚合),scripts(脚本)或 sorting(排序)中使用,而应使用 _uid 字段代替 :

  1. # Example documents
  2. PUT my_index/my_type/1
  3. {
  4. "text": "Document with ID 1"
  5. }
  6. PUT my_index/my_type/2&refresh=true
  7. {
  8. "text": "Document with ID 2"
  9. }
  10. GET my_index/_search
  11. {
  12. "query": {
  13. "terms": {
  14. "_id": [ "1", "2" ] # 1
  15. }
  16. }
  17. }

| 1 | 在 _id 字段上查询(参见 ids 查询) |