2015-05-09 115 views
1

我正在嘗試對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]

我是關閉?這種聚合桶排序可以完成嗎?

回答

2

簡短的回答是,這種對聚合的高級排序尚未得到支持,並且有一個open issue正在解決這個問題(定義爲v2.0.0)。

有兩個值得其他點這裏提的是:

  1. brandName.sort子場被宣佈爲not_analyzed,這是矛盾也設置analyzer在同一時間。

  2. 你得到的錯誤是因爲order部分只能參考子聚合名稱,而不是字段名(即brandName.sort是一個字段名)

+0

謝謝!您是否知道任何解決方法? – Dustin

+0

它有所不同。他們大多數是一兩個字。有些是幾個字。 – Dustin

+0

值得注意的是,我正在使用的數據集足夠小,以便在ElasticSearch中進行客戶端排序後查詢可能比醜陋的黑客更好。 – Dustin