aggs过滤器在弹性searach中不起作用

时间:2016-07-20 06:17:09

标签: elasticsearch

我正在为我的当前项目进行弹性搜索..需要删除重复记录我的O / p如下:

  

阵列   (

[1] => Array
    (
        [_index] => vendors
        [_type] => practiceareas
        [_id] => 582
        [_score] => 
        [_source] => Array
            (
                [practice_area_id] => 364
                [id] => 582
                [practice_area_name] => Joint Pains
                [industry_id] => 9
                [category_id] => 12
            )

    )

[2] => Array
    (
        [_index] => vendors
        [_type] => practiceareas
        [_id] => 1315
        [_score] => 
        [_source] => Array
            (
                [practice_area_id] => 237
                [id] => 1315
                [practice_area_name] => Anemia
                [industry_id] => 9
                [category_id] => 15
            )
    )

[3] => Array
    (
        [_index] => vendors
        [_type] => practiceareas
        [_id] => 2087
        [_score] => 
        [_source] => Array
            (
                [practice_area_id] => 364
                [id] => 2087
                [practice_area_name] => Joint Pains
                [industry_id] => 2
                [category_id] => 12
            )
    )

[4] => Array
    (
        [_index] => vendors
        [_type] => practiceareas
        [_id] => 2820
        [_score] => 
        [_source] => Array
            (
                [practice_area_id] => 237
                [id] => 2820
                [practice_area_name] => Anemia
                [industry_id] => 2
                [category_id] => 15
            )
    )

[5] => Array
    (
        [_index] => vendors
        [_type] => practiceareas
        [_id] => 5312
        [_score] => 
        [_source] => Array
            (
                [practice_area_id] => 364
                [id] => 5312
                [practice_area_name] => Joint Pains
                [industry_id] => 2
                [category_id] => 28
            )
    )

我需要使用practice_area_id / practice_area_name

来消除重复值

我已经厌倦了参考..我的代码如下:

$query = array(
            "from" => $from,
            "size" => $size,
            "sort" => array(array($fieldname => 'desc')),
            "query" => array(
                "filtered" => array(
                    "query" => array("match_all" => array())
                )
            ),
            "aggs" => array(
                "distinct" => array(
                    "terms" => array(
                        "field" => "practice_area_name",
                    )
                )
            )
        );

但它不起作用..请帮我解决一下。在此先感谢。

1 个答案:

答案 0 :(得分:0)

您要删除复制文档,还是只想通过practice_area_name或practice_area_id检查完整的不同文档?

  

对于第二个问题,感知查询看起来像这样

POST vendors/practiceareas/_search
{
    "size": 0, 
    "query": {
        "match_all": {}
    },
    "aggs":{
        "distinct-values":{
            "terms":{
                "field":"practice_area_id",
                "min_doc_count":2
            }
        }
    }
}
  

输出看起来像这样

"aggregations": {
      "distinct-values": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": 364,
               "doc_count": 3
            },
            {
               "key": 237,
               "doc_count": 2
            }
         ]
      }
}