# Field null\_value doesn't seem to have any effect?

**URL:** <https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015>\
**Category:** Elasticsearch\
**Created:** [February 6, 2015, 3:32pm UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015 "2015-02-06T15:32:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AS\_2](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@AS\_2](https://discuss.elastic.co/u/AS_2)\
**Post date:** [February 6, 2015, 3:32pm UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015/1 "2015-02-06T15:32:14Z")

</div>

Hello,

I've configured the null\_value of a field, as below. But when I do a query,  
the documents that lack a barfield, don't return the value "0" for the  
'barfield' as expected. What could be the reason?

```
"foo": {
    "properties": {
        "barfield": {
            "type": "long",
            "store" : true,
            "null_value" : 0
        },
}

```

Regards,

AS.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/509da3e8-0f77-473d-b8e7-becd835f5221%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/509da3e8-0f77-473d-b8e7-becd835f5221%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Michael\_Gallego](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gallego/32/933_2.png) [@Michael\_Gallego](https://discuss.elastic.co/u/Michael_Gallego)\
**Post date:** [February 6, 2015, 3:41pm UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015/2 "2015-02-06T15:41:01Z")

</div>

The null\_value is not used as a "default value", but as a value to used  
when doing searching or aggregations.

For instance, in your mapping, your document will match if you have a  
filter like this: ['term' =\> ['barfield' =\> 0]], however it won't return  
the barfield property if it is null.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8a652e81-2b87-4857-a06c-c522c0fa7bc4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a652e81-2b87-4857-a06c-c522c0fa7bc4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![AS\_2](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@AS\_2](https://discuss.elastic.co/u/AS_2)\
**Post date:** [February 6, 2015, 3:48pm UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015/3 "2015-02-06T15:48:23Z")

</div>

Ah, that explains it. Thx. How can I configure / simulate a default\_value  
for this field?

/AS

On Friday, February 6, 2015 at 4:41:01 PM UTC+1, Michaël Gallego wrote:

> The null\_value is not used as a "default value", but as a value to used  
> when doing searching or aggregations.
> 
> For instance, in your mapping, your document will match if you have a  
> filter like this: ['term' =\> ['barfield' =\> 0]], however it won't return  
> the barfield property if it is null.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3b7d8f0b-f8c6-471f-a8bf-c94346603fad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3b7d8f0b-f8c6-471f-a8bf-c94346603fad%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 6, 2015, 4:06pm UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015/4 "2015-02-06T16:06:56Z")

</div>

Just adding to the previous answer that elasticsearch does not modify the \_source doc.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 6 févr. 2015 à 16:32, AS \*@equanimity.nl a écrit :
> 
> Hello,
> 
> I've configured the null\_value of a field, as below. But when I do a query, the documents that lack a barfield, don't return the value "0" for the 'barfield' as expected. What could be the reason?
> 
> ```
> "foo": {
> "properties": {
> "barfield": {
> "type": "long",
> "store" : true,
> "null_value" : 0
> },
> }
> 
> ```
> 
> Regards,
> 
> AS.
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/509da3e8-0f77-473d-b8e7-becd835f5221%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/509da3e8-0f77-473d-b8e7-becd835f5221%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/F4EFA1AC-EAE4-4124-944F-3A81E08465B6%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/F4EFA1AC-EAE4-4124-944F-3A81E08465B6%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:34am UTC](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015/5 "2017-07-06T00:34:26Z")

</div>


