Elasticsearch(028):es中Meta-Fields(元數據類型)之概述(_id)

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]
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章