ElasticSearch条款聚合订单案例不敏感

时间:2015-05-09 02:56:52

标签: 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]

我关门了吗?可以进行这种聚合桶分类吗?

1 个答案:

答案 0 :(得分:2)

简短的回答是,尚未支持对聚合进行此类高级排序,并且正在解决此问题的open issue(定于v2.0.0)。

这里还有两点值得一提:

  1. brandName.sort子字段被声明为not_analyzed,与同时设置analyzer相矛盾。

  2. 您得到的错误是因为order部分只能引用子聚合名称,而不是字段名称(即brandName.sort是字段名称)

    < / LI>