每个文档都有一个_id唯一标识它的索引,该索引已建立索引,以便可以使用GET API或 ids query查找文档。
不指定的话,es也会默认生成一个id字符串。
_id查询经常用在一下查询中:term, terms,match,query_string,simple_query_string
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深度用户 大家好,我是Leon。一个专业与Java领域的程序员,偶尔理理财。欢迎大家来阅读我博客,如果你发现极个别文章和书籍内容雷同,请叫我勤奋的code搬运工٩(๑❛ᴗ❛๑)۶。我的邮箱:gyoomi0709@foxmail.com