Py学习  »  Elasticsearch

Elasticsearch(028):es中Meta-Fields(元数据类型)之概述(_id)

瘦子没有夏天 • 3 年前 • 270 次点击  

1. 概述

每个文档都有一个_id唯一标识它的索引,该索引已建立索引,以便可以使用GET API或 ids query查找文档。

不指定的话,es也会默认生成一个id字符串。

_id 查询经常用在一下查询中: term, terms,match,query_string,simple_query_string

2. 示例

Mapping定义和插入

PUT example
PUT example/docs/_mapping
{
    "properties":{
        "cityId":{"type": "long"},
        "cityName":{"type": "text"},
        "location":{"type": "geo_point"},
        "remark":{"type": "text"}
    }
}
PUT example/docs/1
{
    "cityId":1,
    "cityName":"xi'an",
    "location": {
        "lat":"34.45",
        "lon":"107.40"
    },
    "remark":"中国旅游城市"

}

PUT example/docs/2
{
    "cityId":2,
    "cityName":"Singapore",
    "location": "1.05,104.60",
    "remark":"世界港口"
}

PUT example/docs/3
{
    "cityId":3,
    "cityName":"Sydney",
    "location": [151.12, -33.51],
    "remark":"澳洲大城"
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

查询

#查询id为1和2的文档
GET example/docs/_search
{
    "query": {
        "terms": {
            "_id": [1, 2]
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/71076
 
270 次点击