2015-05-09 60 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

相关问题