elasticsearch - ElasticSearch条款聚合订单不区分大小写

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

我靠近吗?可以对这种聚合桶进行分类吗?

最佳答案

简短的答案是,尚不支持对聚合进行这种高级排序,并且有一个解决该问题的open issue(计划用于v2.0.0)。

这里还有两点值得一提:

  • 被声明为brandName.sortnot_analyzed子字段,同时设置一个analyzer是矛盾的。
  • 您收到的错误是因为order部分只能引用子聚合名称,而不是字段名称(即brandName.sort是字段名称)
  • 关于elasticsearch - ElasticSearch条款聚合订单不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30135448/

    相关文章:

    curl - 如何使用curl为平面文件测试elasticsearch?

    Elasticsearch 列出所有河流

    python - 对连接的字符串进行标记

    elasticsearch - 如何在Kibana中以条形显示日志中的特定消息

    elasticsearch - 如何在Elasticsearch中搜索字段数组

    json - 使用Elastic Search搜索多个词

    elasticsearch - 无法间歇性连接到 Elastic Search

    elasticsearch - 过滤掉带有仇恨词的 Elasticsearch 结果的最佳解决方案是什么?

    用于连接到 ElasticSearch 的服务器应用程序的 Java 或 Rest API

    elasticsearch - Elasticsearch 查询未返回结果