How to query Null values?


(Kartheek Gummaluri) #1

Hi

I actually loaded data from sql to elasticsearch using logstash jdbc plugin. What I'm facing issue was some of the fields was null and in elasticsearch it is saving as

      "emp_ssnlast4": null

So i'm not able to query

Any help was appreciated

Thanks


#2

Could you try this query :

GET index/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "emp_ssnlast4"
          }
        }
      ]
    }
  }
}

But this will also returns documents where the field emp_ssnlast4 is missing.

What you could also do, is to set a default (placeholder) value in the mapping for null values, then query on this placeholder.

https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html


(Kartheek Gummaluri) #3

so thanks for the reply and the emp_ssnlast4 is integer type how we need to query


#4

If you want to use the null_value parameter for an integer (the value must be the same datatype), so you could set 0 or -1, depending on your logic?


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.