0

Data in my elasticsearch contains a field named facilityName. I have a requirement where I have to see if there are any duplicate records with facilityNameTypeCode as "UWI" and having same facilityName value. Following is a structure example:

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

This is the query I created:

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

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

But I am having this error:

{
  "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
}

Can anyone suggest on how to do this?

rishav
  • 441
  • 9
  • 27

1 Answers1

0

The error is pretty clear

[size] must be greater than 0. Found [0] in [duplicateNames]

So simply set size to something bigger than 0, it doesn't make much sense to set it to 0 anyway

        "terms": {
          "field": "facilityName.facilityName",
          "size": 10,
          "min_doc_count": 2
        }
Val
  • 207,596
  • 13
  • 358
  • 360
  • I have the same issue, I think he was trying to get unlimited result instead of 10 documents by default – tsu Apr 18 '20 at 15:14