elasticsearch查询+agg搜索查询

ryevplcw  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(531)

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
}

有人能建议怎么做吗?

x7rlezfr

x7rlezfr1#

错误很明显
[大小]必须大于0。在[duplicatenames]中找到[0]
所以简单地将size设置为大于0的值,不管怎样设置为0也没有多大意义

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

相关问题