我正在嘗試對elasticsearch中的術語聚合的桶進行排序,不區分大小寫。這裏是字段映射:ElasticSearch術語聚合順序不區分大小寫
'brandName' => [
'type' => 'string',
'analyzer' => 'english',
'index' => 'analyzed',
'fields' => [
'raw' => [
'type' => 'string',
'index' => 'not_analyzed'
]
]
]
注意的是,這裏這個數據結構是PHP。
和聚合看起來是這樣的:
aggregations => [
'brands' => [
'terms' => [
'field' => 'brandName.raw',
'size' => 0,
'order' => ['_term' => 'asc']
]
]
]
這工作,但由此產生的桶是字典序。
我發現了一些有趣的文檔here,它解釋瞭如何做到這一點,但它是在排序命中的情況下,而不是聚合桶。
無論如何我都試過了。這裏是我創建的分析儀:
'analysis' => [
'analyzer' => [
'case_insensitive_sort' => [
'tokenizer' => 'keyword',
'filter' => [ 'lowercase' ]
]
]
]
這裏是更新的字段映射,帶有使用分析器的稱爲「sort」的新子字段。
'brandName' => [
'type' => 'string',
'analyzer' => 'english',
'index' => 'analyzed',
'fields' => [
'raw' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'sort' => [
'type' => 'string',
'index' => 'not_analyzed',
'analyzer' => 'case_insensitive_sort'
]
]
]
這是我的查詢的更新彙總部分:
aggregations => [
'brands' => [
'terms' => [
'field' => 'brandName.raw',
'size' => 0,
'order' => ['brandName.sort' => 'asc']
]
]
]
這會產生以下錯誤:Invalid term-aggregator order path [brandName.sort]. Unknown aggregation [brandName]
。
我是關閉?這種聚合桶排序可以完成嗎?
謝謝!您是否知道任何解決方法? – Dustin
它有所不同。他們大多數是一兩個字。有些是幾個字。 – Dustin
值得注意的是,我正在使用的數據集足夠小,以便在ElasticSearch中進行客戶端排序後查詢可能比醜陋的黑客更好。 – Dustin