2017-06-04 185 views
1

如果有任何方法或設置在elasticsearch中執行按字母排序,我有一個領域,我想按降序進行排序。 Elastic按字典順序執行。我能得到什麼:使用elasticsearch按字母順序排序

Company name 
Customer name 
company address 

我想:

Company name 
company address 
Customer name 

我發現我可以創建自定義分析,但也許可以有更好的選擇?

+0

如果你不使用任何分析Elasticsearch使用標準分析儀,它有一個小寫的過濾器。在這種情況下,我想,你會得到正確的排序結果。但是這個結果不適用於unicode字符。如果您沒有看到,可以查看https://www.elastic.co/guide/en/elasticsearch/guide/current/sorting-collat​​ions.html文章。 – hkulekci

+0

是啊激動,@Yauheni你可以建立不同的分析儀的領域,然後你可以告訴我排序在該領域。 – user3775217

回答

0

使用multifields將文本字段索引爲帶字段數據的小寫關鍵字,您可以對其進行排序。

{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "keyword_lowercase": { 
      "tokenizer": "keyword", 
      "filter": ["lowercase"] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "my_type": { 
     "properties": { 
     "text": { 
      "type": "text", 
      "fields": { 
      "raw": { 
       "type":  "text", 
       "analyzer": "keyword_lowercase", 
       "fielddata": true 
      } 
      } 
     } 
     } 
    } 
    } 
} 

查詢

{ 
    "sort": [ 
    { 
     "text.raw": { 
     "order": "asc" 
     } 
    } 
    ] 
}