gpt4 book ai didi

elasticsearch - 避免在 Elasticsearch 结果中重复

转载 作者:行者123 更新时间:2023-12-02 22:39:06 26 4
gpt4 key购买 nike

我有以下数据,我想避免结果中重复练习区名称。如何在 flex 搜索结果中避免重复。请寄给我解决方案。

Array
(
[0] => Array
(
[_index] => vendors
[_type] => practiceareas
[_id] => 240
[_score] =>
[_source] => Array
(
[practice_area_id] => 237
[id] => 240
[practice_area_name] => Anemia
[practice_area_image] =>
[created_date] => 2016-07-04 14:51:46
[status] => 1
[industry_id] => 9
[category_id] => 14
[vendors_count] => 26
[services_count] => 0
[products_count] => 0
)

[sort] => Array
(
[0] => 26
)

)

[1] => Array
(
[_index] => vendors
[_type] => practiceareas
[_id] => 582
[_score] =>
[_source] => Array
(
[practice_area_id] => 364
[id] => 582
[practice_area_name] => Joint Pains
[practice_area_image] =>
[created_date] => 2016-07-04 14:51:47
[status] => 1
[industry_id] => 9
[category_id] => 12
[vendors_count] => 26
[services_count] => 0
[products_count] => 0
)

[sort] => Array
(
[0] => 26
)

)

[2] => Array
(
[_index] => vendors
[_type] => practiceareas
[_id] => 1315
[_score] =>
[_source] => Array
(
[practice_area_id] => 237
[id] => 1315
[practice_area_name] => Anemia
[practice_area_image] =>
[created_date] => 2016-07-04 14:51:46
[status] => 1
[industry_id] => 9
[category_id] => 15
[vendors_count] => 26
[services_count] => 0
[products_count] => 0
)

[sort] => Array
(
[0] => 26
)

)
)

谢谢。

最佳答案

您可能想使用Field Collapsing来显示按特定字段分组的搜索结果。按名称分组意味着需要术语聚合。

为了能够对“practice_area_name”进行分组,该字段应以其原始not_analyzed形式可用。否则,您应该对“practice_area_id”进行分组以避免not_analyzed字段。

"aggs": {
"vendors": {
"terms": {
"field": "practice_area_name"
},
"aggs": {
"dedup_docs": { "top_hits": { "size": 1 }}
}
}
}

注意:top_score聚合按每个存储区中得分最高的文档对用户聚合中的术语进行排序。

关于elasticsearch - 避免在 Elasticsearch 结果中重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38494665/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com