# Null\_value not working

**URL:** <https://discuss.elastic.co/t/null-value-not-working/166785>\
**Category:** Elasticsearch\
**Created:** [February 1, 2019, 8:49pm UTC](https://discuss.elastic.co/t/null-value-not-working/166785 "2019-02-01T20:49:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoZomIBK](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@NoZomIBK](https://discuss.elastic.co/u/NoZomIBK)\
**Post date:** [February 1, 2019, 8:49pm UTC](https://discuss.elastic.co/t/null-value-not-working/166785/1 "2019-02-01T20:49:41Z")

</div>

I have an integer field which may be null and should have the null\_value 0. for testing i prepared an index:

> curl -H "Content-Type: application/json" -XPUT -d "{"mappings":{"\_doc":{"properties":{"name":{"type":"text"},"documentCounter":{"type":"integer","null\_value":0}}}}}" localhost:9200/nulltest

and added one doc:

> curl -H "Content-Type: application/json" -XPUT -d "{"name":"Some name"}" localhost:9200/nulltest/\_doc/1

it can be queried without problems:

> curl localhost:9200/nulltest/\_doc/1

> {"\_index":"nulltest","\_type":"\_doc","\_id":"1","\_version":1,"found":true,"\_source":{"name":"Some name"}}

i would expect it to be found by this search:

> curl -H "Content-Type: application/json" -XPOST -d "{"query":{"bool":{"must":[{"term":{"documentCounter":0}}]}}}" localhost:9200/nulltest/\_search

but the response has no hits

> {"took":5,"timed\_out":false,"\_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}

and on top of this there is a bigger problem for me. When using the documentCounter field in a function it happens to fail depending on the client (which seems strange).

> curl -H "Content-Type: application/json" -XPOST -d "{"from":0,"size":8192,"query":{"bool":{"must":[{"function\_score":{"query":{"bool":{"should":[{"match":{"name":{"query":"Somename","operator":"AND","fuzziness":"0","prefix\_length":0,"max\_expansions":50,"fuzzy\_transpositions":true,"lenient":false,"zero\_terms\_query":"NONE","cutoff\_frequency":0.35,"auto\_generate\_synonyms\_phrase\_query":true,"boost":2}}}],"adjust\_pure\_negative":true,"boost":1}},"functions":[{"filter":{"match\_all":{"boost":1}},"field\_value\_factor":{"field":"documentCounter","factor":1,"modifier":"log1p"}}],"score\_mode":"sum","max\_boost":3.4028235e+38,"boost":1}}],"adjust\_pure\_negative":true,"boost":1}},"version":true,"sort":[{"\_score":{"order":"desc"}}]}" localhost:9200/nulltest/\_search

the response with curl is:

> {"took":4,"timed\_out":false,"\_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max\_score":null,"hits":}}

when i make the exact same query with the chrome addon "elasticsearch head" one shard failes:

> {"took": 5,"timed\_out": false,"\_shards": {"total": 5,"successful": 4,"skipped": 0,"failed": 1,"failures": [{"shard": 3,"index": "nulltest","node": "6vOdvUnpQ6u9BciVk7LwFw","reason": {"type": "exception","reason": "Missing value for field [documentCounter]"}}]},"hits": {"total": 0,"max\_score": null,"hits": }}

when i make this request with the elasticsearch java-client 6.5.3 the whole call fails with all shards failed:

> {"error":{"root\_cause":[{"type":"exception","reason":"Missing value for field [documentCounter]"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"nulltest","node":"6vOdvUnpQ6u9BciVk7LwFw","reason":{"type":"exception","reason":"Missing value for field [documentCounter]"}}]},"status":500}

i ran the searches with the three clients multiple times in all orders without any change in the results.

My server runs on 6.4.2

the expected behaviour would be:

1. search for documentcounter:0 to return the document
2. no failures of the search with the filter and same behaviour for same queries in different clients

---

<div class="post-metadata">

**Author:** ![NoZomIBK](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@NoZomIBK](https://discuss.elastic.co/u/NoZomIBK)\
**Post date:** [February 5, 2019, 10:01am UTC](https://discuss.elastic.co/t/null-value-not-working/166785/2 "2019-02-05T10:01:23Z")

</div>

Server updated to 6.6.0 did not resolve the problem either

---

<div class="post-metadata">

**Author:** ![NoZomIBK](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@NoZomIBK](https://discuss.elastic.co/u/NoZomIBK)\
**Post date:** [February 6, 2019, 2:26pm UTC](https://discuss.elastic.co/t/null-value-not-working/166785/3 "2019-02-06T14:26:56Z")

</div>

Ok, the issue was, the documentCounter was not set explicit to null. i would preferr for it working on missing values, too, or at least having an option for this.

But the documentation ([null\_value | Elasticsearch Guide [6.6] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/null-value.html)) is a bit wrong. null, empty array and array with only null values should be set to the null\_value.

> When a field is set to `null` , (or an empty array or an array of `null` values) it is treated as though that field has no values.

But in the example the empty array does not trigger the null\_value to be inserted

> An empty array does not contain an explicit `null` , and so won’t be replaced with the `null_value` .

---

<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:** [March 6, 2019, 2:27pm UTC](https://discuss.elastic.co/t/null-value-not-working/166785/4 "2019-03-06T14:27:07Z")

</div>

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