# Grouping by keys that include nil values

**URL:** <https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982>\
**Category:** Elasticsearch\
**Created:** [February 5, 2015, 1:31am UTC](https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982 "2015-02-05T01:31:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehul\_Kar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehul_kar/32/936_2.png) [@Mehul\_Kar](https://discuss.elastic.co/u/Mehul_Kar)\
**Post date:** [February 5, 2015, 1:31am UTC](https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982/1 "2015-02-05T01:31:06Z")

</div>

Hello,

I'm looking to query an index for groups by a specific key. There are  
documents that have nil values in in these queries, and by default ES  
doesn't return these records in the aggregations key of the response.

I've tried applying a `missing` filter, and it looks like the `hits` key in  
the response includes all the records, but the aggregations key does not.

What is a good strategy for this? Will I have to post process these  
results? Index blank strings for nil values?

--  
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/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Mehul\_Kar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mehul_kar/32/936_2.png) [@Mehul\_Kar](https://discuss.elastic.co/u/Mehul_Kar)\
**Post date:** [February 5, 2015, 1:40am UTC](https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982/2 "2015-02-05T01:40:32Z")

</div>

Ideally, I'd like to see these records grouped under a nil key or something  
automatically.

* * *

Mehul Kar  
@mehulkar

On Wed, Feb 4, 2015 at 5:31 PM, Mehul Kar [mehul.kar@gmail.com](mailto:mehul.kar@gmail.com) wrote:

> Hello,
> 
> I'm looking to query an index for groups by a specific key. There are  
> documents that have nil values in in these queries, and by default ES  
> doesn't return these records in the aggregations key of the response.
> 
> I've tried applying a `missing` filter, and it looks like the `hits` key  
> in the response includes all the records, but the aggregations key does  
> not.
> 
> What is a good strategy for this? Will I have to post process these  
> results? Index blank strings for nil values?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/wfMqQZGW2Ng/unsubscribe](https://groups.google.com/d/topic/elasticsearch/wfMqQZGW2Ng/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> 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/CAG7%3DhdizQ0198fLhs9EZSUUBwk6FrLM%3Dvg-LtQ2HnV\_WLWirrg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAG7%3DhdizQ0198fLhs9EZSUUBwk6FrLM%3Dvg-LtQ2HnV_WLWirrg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![javadevmtl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javadevmtl/32/45613_2.png) [@javadevmtl](https://discuss.elastic.co/u/javadevmtl)\
**Post date:** [February 6, 2015, 3:00pm UTC](https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982/3 "2015-02-06T15:00:30Z")

</div>

You would need to use a placeholder value. So if you know the value is NULL  
or empty then insert the document with a string value of NIL or N/A or  
something...

On Wednesday, 4 February 2015 20:41:18 UTC-5, Mehul Kar wrote:

> Ideally, I'd like to see these records grouped under a nil key or  
> something automatically.
> 
> * * *
> 
> Mehul Kar  
> @mehulkar
> 
> On Wed, Feb 4, 2015 at 5:31 PM, Mehul Kar \<[mehu...@gmail.com](mailto:mehu...@gmail.com) \<javascript:\>
> 
> > wrote:
> 
> > Hello,
> > 
> > I'm looking to query an index for groups by a specific key. There are  
> > documents that have nil values in in these queries, and by default ES  
> > doesn't return these records in the aggregations key of the response.
> > 
> > I've tried applying a `missing` filter, and it looks like the `hits` key  
> > in the response includes all the records, but the aggregations key does  
> > not.
> > 
> > What is a good strategy for this? Will I have to post process these  
> > results? Index blank strings for nil values?
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/wfMqQZGW2Ng/unsubscribe](https://groups.google.com/d/topic/elasticsearch/wfMqQZGW2Ng/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/907ce471-59a7-4832-bd42-e1bf3fc28833%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > 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/c63ce3c1-3c70-4716-90eb-78b973ff5290%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c63ce3c1-3c70-4716-90eb-78b973ff5290%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:34am UTC](https://discuss.elastic.co/t/grouping-by-keys-that-include-nil-values/21982/4 "2017-07-06T00:34:29Z")

</div>


