Elasticsearch(028):es中Meta-Fields(元数据类型)之概述(_id)
程序员文章站
2022-04-23 22:17:35
...
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":"澳洲大城"
}
查询
#查询id为1和2的文档
GET example/docs/_search
{
"query": {
"terms": {
"_id": [1, 2]
}
}
}
上一篇: java配置 [配置扫描]