Elasticsearch查询+ Agg搜索查询

时间:2019-01-04 08:22:53

标签: elasticsearch elasticsearch-aggregation elasticsearch-query

elasticsearch中的数据包含一个名为facilityName的字段。我有一个要求,我必须查看是否有facilityNameTypeCode为“ UWI”且具有相同的facilityName值的重复记录。以下是一个结构示例:

    "facilityName": [
      {
        "facilityNameTypeId": {
          "facilityNameTypeCode": "Name"
        },
        "facilityName": "Rishav jayswal"
      },
      {
        "facilityNameTypeId": {
          "facilityNameTypeCode": "Name"
        },
        "facilityName": "R.M"
      }
  ]

这是我创建的查询:

GET _search
{
    "query" : {
        "term" : {"facilityName.facilityNameTypeId.facilityNameTypeCode" : "UWI"}
    },

    "aggs" : {
        "duplicateNames": {
            "terms": {
                        "field": "facilityName.facilityName",
                        "size": 0,
                        "min_doc_count": 2
                    }
            }
    }
}

但是我遇到了这个错误:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[terms] failed to parse field [size]",
        "line": 10,
        "col": 27
      }
    ],
    "type": "parsing_exception",
    "reason": "[terms] failed to parse field [size]",
    "line": 10,
    "col": 27,
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "[size] must be greater than 0. Found [0] in [duplicateNames]"
    }
  },
  "status": 400
}

有人可以建议如何做吗?

1 个答案:

答案 0 :(得分:0)

错误很明显

  

[大小]必须大于0。在[duplicateNames]中找到[0]

因此,只需将大小设置为大于0的值,将其设置为0并没有多大意义

        "terms": {
          "field": "facilityName.facilityName",
          "size": 10,
          "min_doc_count": 2
        }