我正在尝试在不区分大小写的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]
。我靠近吗?可以对这种聚合桶进行分类吗?
最佳答案
简短的答案是,尚不支持对聚合进行这种高级排序,并且有一个解决该问题的open issue(计划用于v2.0.0)。
这里还有两点值得一提:
brandName.sort
的not_analyzed
子字段,同时设置一个analyzer
是矛盾的。 order
部分只能引用子聚合名称,而不是字段名称(即brandName.sort
是字段名称)关于elasticsearch - ElasticSearch条款聚合订单不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30135448/