multi-fields
It is often useful to index the same field in different ways for different purposes. This is the purpose of multi-fields. For instance, a string field could be mapped as a text field for full-text search, and as a keyWord field for sorting or aggregations. You can define as many fields with the fields parameter as you want. Please note that this option is only available for core data types and not for the objects.
對一個field設置多種索引方式。比如,一個字符串設置為”text”類型用于進行全文檢索,同時又給它設置”keyword”類型用于排序或聚合。
#對需要設置的字段,在'type'屬性后增加"fields": #其中的"raw"為自定義的名稱,想象它是city的一個分身。PUT /my_index{ "mappings": { "my_type": { "PRoperties": { "city": { "type": "text", "fields": { "raw": { "type": "keyword" } } } } } }}插入數(shù)據(jù)
PUT /my_index/my_type/1{ "city": "New York"}PUT /my_index/my_type/2{ "city": "York"}查詢并排序 查詢字段為city,使用它的text類型.排序使用了city.raw
GET /my_index/_search{ "query": { "match": { "city": "York" } }, "sort": { "city.raw": "asc" }}新聞熱點
疑難解答