Elasticsearch术语聚合排序

时间:2015-08-13 09:39:35

标签: elasticsearch

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

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

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

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

这很好,但作为elasticsearch文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order

陈述,这将返回按每个桶的文档数排序的不同ID列表。

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

谢谢!

1 个答案:

答案 0 :(得分:1)

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

将top_hits聚合添加到术语聚合包括最高得分文档及其对应的分数:

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

相关问题