【问题标题】:Elasticsearch Terms aggregation orderingElasticsearch 术语聚合排序
【发布时间】:2015-11-06 05:00:21
【问题描述】:

我们目前正在开发多语言文档 CMS。因此,我们有翻译成不同语言的文件。

为了使用 Elasticsearch 进行搜索,我们目前对每种语言(德语、英语、法语……)使用一个索引,其中同一文档的所有翻译共享相同的 ID。

当用户搜索特定术语时,我们希望在所有语言中进行搜索,但只返回不同 ID 的列表。据我所知,这只能通过使用以下术语聚合来实现:

curl localhost:9200/german,english,french/_search?pretty=1 -d 
'{
    "aggs": {
        "asset_ids": {
            "terms": {
                "field": "_id"
            }
        }
    }
}'

这工作正常,但作为弹性搜索文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order

声明,这将返回一个不同 ID 的列表,该列表按每个存储桶的文档数排序。

我的问题是:是否可以从多个索引中检索不同 ID 的列表,其中所述 ID 按它们所代表的文档的相关性排序?或者对于我们的场景是否有更好的方法?

谢谢!

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    如果有人对我们如何解决这个问题感兴趣,我现在将给出一个可能的解决方案。这可能不是解决问题的最佳方法。

    将 top_hits 聚合添加到 terms 聚合中,包括得分最高的文档及其在存储桶中的对应分数:

    curl localhost:9200/german,english,french/_search?pretty=1 -d 
    '{
        "aggs": {
            "asset_ids": {
                "terms": {
                    "field": "_id"
                },
                "aggregations": {
                    "top_id_hits": {
                        "top_hits": {}
                    }
                }
            }
        }
    }'
    

    按照最佳评分文档(又名 max_score)对检索到的存储桶进行排序最终可以解决问题。

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 2021-06-06
      • 1970-01-01
      • 2021-06-06
      • 2015-01-21
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多