# How to response null value fields when query using "fields"

**URL:** <https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686>\
**Category:** Elasticsearch\
**Created:** [May 26, 2015, 7:11am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686 "2015-05-26T07:11:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [May 26, 2015, 7:11am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/1 "2015-05-26T07:11:51Z")

</div>

I used "fields" to limit only return selected fields:  
{  
"fields" : ["Title", "Price"],  
"query" :{  
...  
}  
}

The Price fields might be null for some of the documents, I found that only  
when "Price" field value is NOT null, it is returned in ES response,  
otherwise, it is missing in response. But if I remove "fields" from the  
query, the null value field will appear in response.

Is it by design of Elasticsearch? How to return the null value fields in  
response even using "fields" in query?

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Allan\_Mitchell](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Allan\_Mitchell](https://discuss.elastic.co/u/Allan_Mitchell)\
**Post date:** [May 26, 2015, 8:19am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/2 "2015-05-26T08:19:11Z")

</div>

Hi

If you have a field that has null as a value then as far as the inverted  
index is concerned for that document it doesn''t exist

Have a look at this

> **[Dealing with Null Values | Elasticsearch: The Definitive Guide \[2.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)**

On 26 May 2015 at 08:11, Xudong You [xudong.you@gmail.com](mailto:xudong.you@gmail.com) wrote:

> I used "fields" to limit only return selected fields:  
> {  
> "fields" : ["Title", "Price"],  
> "query" :{  
> ...  
> }  
> }
> 
> The Price fields might be null for some of the documents, I found that  
> only when "Price" field value is NOT null, it is returned in ES response,  
> otherwise, it is missing in response. But if I remove "fields" from the  
> query, the null value field will appear in response.
> 
> Is it by design of Elasticsearch? How to return the null value fields in  
> response even using "fields" in query?
> 
> ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> 
> 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/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/CAECdJzD0GgOE2wz2uoZ974AZtP4BbB%2BK%3DOUbbz5HTQ8rCKh9oA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAECdJzD0GgOE2wz2uoZ974AZtP4BbB%2BK%3DOUbbz5HTQ8rCKh9oA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [May 26, 2015, 8:33am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/3 "2015-05-26T08:33:09Z")

</div>

Thanks your reply!  
But why if I remove "fields" from query DSL, then I can see those null  
value fields in ES response?

On Tuesday, May 26, 2015 at 4:19:30 PM UTC+8, Allan Mitchell wrote:

> Hi
> 
> If you have a field that has null as a value then as far as the inverted  
> index is concerned for that document it doesn''t exist
> 
> Have a look at this
> 
> [Dealing with Null Values | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)
> 
> On 26 May 2015 at 08:11, Xudong You \<[xudon...@gmail.com](mailto:xudon...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > I used "fields" to limit only return selected fields:  
> > {  
> > "fields" : ["Title", "Price"],  
> > "query" :{  
> > ...  
> > }  
> > }
> > 
> > The Price fields might be null for some of the documents, I found that  
> > only when "Price" field value is NOT null, it is returned in ES response,  
> > otherwise, it is missing in response. But if I remove "fields" from the  
> > query, the null value field will appear in response.
> > 
> > Is it by design of Elasticsearch? How to return the null value fields in  
> > response even using "fields" in query?
> > 
> > ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> > 
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Allan\_Mitchell](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@Allan\_Mitchell](https://discuss.elastic.co/u/Allan_Mitchell)\
**Post date:** [May 26, 2015, 8:45am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/4 "2015-05-26T08:45:35Z")

</div>

Hi

Here is a quick example (pinched from the article I sent you and added to)

You can see that we get the values from two different places. Whilst the  
field exists at the \_all level it does not exist in the inverted index.

POST /my\_index/posts/\_bulk  
{ "index": { "\_id": "1" }}  
{ "tags" : ["search"] }  
{ "index": { "\_id": "2" }}  
{ "tags" : ["search", "open\_source"] }  
{ "index": { "\_id": "3" }}  
{ "other\_field" : "some data" }  
{ "index": { "\_id": "4" }}  
{ "tags" : null }  
{ "index": { "\_id": "5" }}  
{ "tags" : ["search", null] }

GET /my\_index/\_search

GET /my\_index/\_search  
{  
"fields": [  
"tags"  
],  
"query": { "match\_all": {}}

}

On 26 May 2015 at 09:33, Xudong You [xudong.you@gmail.com](mailto:xudong.you@gmail.com) wrote:

> Thanks your reply!  
> But why if I remove "fields" from query DSL, then I can see those null  
> value fields in ES response?
> 
> On Tuesday, May 26, 2015 at 4:19:30 PM UTC+8, Allan Mitchell wrote:
> 
> > Hi
> > 
> > If you have a field that has null as a value then as far as the inverted  
> > index is concerned for that document it doesn''t exist
> > 
> > Have a look at this
> > 
> > [Dealing with Null Values | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)
> > 
> > On 26 May 2015 at 08:11, Xudong You [xudon...@gmail.com](mailto:xudon...@gmail.com) wrote:
> > 
> > > I used "fields" to limit only return selected fields:  
> > > {  
> > > "fields" : ["Title", "Price"],  
> > > "query" :{  
> > > ...  
> > > }  
> > > }
> > > 
> > > The Price fields might be null for some of the documents, I found that  
> > > only when "Price" field value is NOT null, it is returned in ES response,  
> > > otherwise, it is missing in response. But if I remove "fields" from the  
> > > query, the null value field will appear in response.
> > > 
> > > Is it by design of Elasticsearch? How to return the null value fields in  
> > > response even using "fields" in query?
> > > 
> > > ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> > > 
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> 
> * * *
> 
> 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/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/CAECdJzCt\_%2BVvB8JqWRfT7Xs-9%3DHb\_Jg-s6Yxarq%2B01b9mn5ggg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAECdJzCt_%2BVvB8JqWRfT7Xs-9%3DHb_Jg-s6Yxarq%2B01b9mn5ggg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [May 27, 2015, 4:14pm UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/5 "2015-05-27T16:14:13Z")

</div>

Thanks. Understand now.

On Tuesday, May 26, 2015 at 4:46:47 PM UTC+8, Allan Mitchell wrote:

> Hi
> 
> Here is a quick example (pinched from the article I sent you and added to)
> 
> You can see that we get the values from two different places. Whilst the  
> field exists at the \_all level it does not exist in the inverted index.
> 
> POST /my\_index/posts/\_bulk  
> { "index": { "\_id": "1" }}  
> { "tags" : ["search"] }  
> { "index": { "\_id": "2" }}  
> { "tags" : ["search", "open\_source"] }  
> { "index": { "\_id": "3" }}  
> { "other\_field" : "some data" }  
> { "index": { "\_id": "4" }}  
> { "tags" : null }  
> { "index": { "\_id": "5" }}  
> { "tags" : ["search", null] }
> 
> GET /my\_index/\_search
> 
> GET /my\_index/\_search  
> {  
> "fields": [  
> "tags"  
> ],  
> "query": { "match\_all": {}}
> 
> }
> 
> On 26 May 2015 at 09:33, Xudong You \<[xudon...@gmail.com](mailto:xudon...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Thanks your reply!  
> > But why if I remove "fields" from query DSL, then I can see those null  
> > value fields in ES response?
> > 
> > On Tuesday, May 26, 2015 at 4:19:30 PM UTC+8, Allan Mitchell wrote:
> > 
> > > Hi
> > > 
> > > If you have a field that has null as a value then as far as the inverted  
> > > index is concerned for that document it doesn''t exist
> > > 
> > > Have a look at this
> > > 
> > > [Dealing with Null Values | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)
> > > 
> > > On 26 May 2015 at 08:11, Xudong You [xudon...@gmail.com](mailto:xudon...@gmail.com) wrote:
> > > 
> > > > I used "fields" to limit only return selected fields:  
> > > > {  
> > > > "fields" : ["Title", "Price"],  
> > > > "query" :{  
> > > > ...  
> > > > }  
> > > > }
> > > > 
> > > > The Price fields might be null for some of the documents, I found that  
> > > > only when "Price" field value is NOT null, it is returned in ES response,  
> > > > otherwise, it is missing in response. But if I remove "fields" from the  
> > > > query, the null value field will appear in response.
> > > > 
> > > > Is it by design of Elasticsearch? How to return the null value fields  
> > > > in response even using "fields" in query?
> > > > 
> > > > ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> > > > 
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3c91fd31-0e13-4afb-a9bf-1a0ec795e68f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > Please update your bookmarks! We have moved to  
> > > [https://discuss.elastic.co/](https://discuss.elastic.co/)
> > 
> > * * *
> > 
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/71e4219a-e9a6-4fa0-a289-9bf3fb6e50a3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/e80d5718-8dfd-4775-9f80-f02977195329%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e80d5718-8dfd-4775-9f80-f02977195329%40googlegroups.com).  
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:11am UTC](https://discuss.elastic.co/t/how-to-response-null-value-fields-when-query-using-fields/23686/6 "2017-07-06T00:11:33Z")

</div>


