避免在弹性搜索结果中重复

时间:2016-07-21 04:02:30

标签: elasticsearch

我有下面的数据我想避免在结果中重复练习区域名称如何在我的弹性搜索结果中避免重复。请发送给我解决方案。

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
                )

        )
)

感谢。

1 个答案:

答案 0 :(得分:0)

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

为了能够对' practice_area_name'进行分组,该字段应以原始not_analyzed形式提供。否则,您应该分组' practice_area_id'避免"aggs": { "vendors": { "terms": { "field": "practice_area_name" }, "aggs": { "dedup_docs": { "top_hits": { "size": 1 }} } } } 字段。

{{1}}

注意:top_score聚合通过每个存储桶中的得分最高的文档对用户聚合中的条款进行排序。