# How to query Null values?

**URL:** <https://discuss.elastic.co/t/how-to-query-null-values/135253>\
**Category:** Elasticsearch\
**Created:** [June 10, 2018, 6:41am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253 "2018-06-10T06:41:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [June 10, 2018, 6:41am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253/1 "2018-06-10T06:41:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 10, 2018, 7:15am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253/2 "2018-06-10T07:15:38Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html)

---

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [June 10, 2018, 8:35am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253/3 "2018-06-10T08:35:44Z")

</div>

so thanks for the reply and the emp\_ssnlast4 is integer type how we need to query

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [June 10, 2018, 9:43am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253/4 "2018-06-10T09:43:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 8, 2018, 9:43am UTC](https://discuss.elastic.co/t/how-to-query-null-values/135253/5 "2018-07-08T09:43:20Z")

</div>

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