我正在尝试对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