# \[ElasticSearch Query\] Select all not null fields

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340>\
**Category:** Elasticsearch\
**Created:** [August 1, 2019, 2:06pm UTC](https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340 "2019-08-01T14:06:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amoussoubaruch](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@amoussoubaruch](https://discuss.elastic.co/u/amoussoubaruch)\
**Post date:** [August 1, 2019, 2:06pm UTC](https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340/1 "2019-08-01T14:06:54Z")

</div>

Hi evryone,

I face some issue and i don't really know how i can solve that.  
I have one index with more than 600 fields. Sometimes i can have arround 500 fields with null values. I want to make a select query and have a result without all null fields.

For exemple, suppose i have this index :

{  
"took": 11,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 4392822,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "test\_index",  
"\_type": "test\_indextype",  
"\_id": "MHbBSGwBfQlFPBBvF79Y",  
"\_score": 1,  
"\_source": {  
"field1": "Value1",  
"f\_id": "17AEBA",  
"code": "DT10",  
"l\_uc": "INJ1",  
"d\_id": 23765,  
"Info1": null,  
"Info2": null,  
"Info3": null,  
"Info4": null,  
"Info5": null,  
"Info6": null,  
"Info7": null,  
"Info8": null,  
"Info9": null,  
"Info10": null,  
"Info11": null,  
"Info12": null,  
"Info13": null,  
"Info14": null,  
"Info15": null,  
"Info16": null  
}}

I want a query to have only this :

{  
"took": 11,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 4392822,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "test\_index",  
"\_type": "test\_indextype",  
"\_id": "MHbBSGwBfQlFPBBvF79Y",  
"\_score": 1,  
"\_source": {  
"field1": "Value1",  
"f\_id": "17AEBA",  
"code": "DT10",  
"l\_uc": "INJ1",  
"d\_id": 23765}}

Thanks in advance

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [August 1, 2019, 2:36pm UTC](https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340/2 "2019-08-01T14:36:10Z")

</div>

Hi @amoussoubaruch,

I think the more easy way to remove the fields that are null form the result is to not index them.  
It can save disk space.

You can add an ingest with remove processor that will drop the null fields with condition.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/remove-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/remove-processor.html)  
Or depend on how you get your data it maybe more easy to just drop them before indexing.

---

<div class="post-metadata">

**Author:** ![amoussoubaruch](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@amoussoubaruch](https://discuss.elastic.co/u/amoussoubaruch)\
**Post date:** [August 1, 2019, 3:44pm UTC](https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340/3 "2019-08-01T15:44:18Z")

</div>

Hi @gabriel_tessier,

Thanks for your reply. I will test it and get back to you as soon as.

---

<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:** [August 29, 2019, 3:44pm UTC](https://discuss.elastic.co/t/elasticsearch-query-select-all-not-null-fields/193340/4 "2019-08-29T15:44:26Z")

</div>

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