Home > Net >  Empty field request
Empty field request

Time:01-26

so I have a GET request and I need to filter documents with empty fields, is there any way I can do that in ES because I know you can't search for empty fields, will a filter work the same as search? this document field is actually a 2D array in Elastic search.

curl -X GET -H "Content-Type: application/json" "localhost.blahblah/" -d '{"query":{ "bool": {"filter": {"terms":{ "documents":[ "" ] } } } }}'

curl -X GET -H "Content-Type: application/json" "my_index/" -d '{"query":{ "bool": {"filter": {"terms":{ "documents":[ "" ] } } } }}'

CodePudding user response:

Try the code bellow:

{
  "query": {
    "bool": {
      "must_not": [
        {
          "wildcard": {
            "documents": {
              "value": "*"
            }
          }
        }
      ]
    }
  }
}

CodePudding user response:

Use the exists query along with the must_not boolean query to locate documents that are missing an indexed value(can be empty or null) for a field.

Query:

{
  "query": {
  "bool" : {
    "must_not": [
      {
        "exists": {
          "field": "documents"
        }
      }
    ]
  }
  • Related