# Conditional Include and Exclude Fields

**URL:** <https://discuss.elastic.co/t/conditional-include-and-exclude-fields/129403>\
**Category:** Elasticsearch\
**Created:** [April 25, 2018, 5:16am UTC](https://discuss.elastic.co/t/conditional-include-and-exclude-fields/129403 "2018-04-25T05:16:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronit\_dhingra](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@ronit\_dhingra](https://discuss.elastic.co/u/ronit_dhingra)\
**Post date:** [April 25, 2018, 5:16am UTC](https://discuss.elastic.co/t/conditional-include-and-exclude-fields/129403/1 "2018-04-25T05:16:26Z")

</div>

I am using Terms Aggregation for x-axis.  
and splitting the series on a specific condition.  
some terms in x-axis dos not have the field on which split is applied. Can i order the aggregation in such a way that only the terms with that specific field shows up First in the axis or any way to conditionally remove them.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 27, 2018, 9:45am UTC](https://discuss.elastic.co/t/conditional-include-and-exclude-fields/129403/2 "2018-04-27T09:45:28Z")

</div>

> [@ronit\_dhingra](#):
>
> or any way to conditionally remove them.

Can you use the [exists query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html) to remove docs without the secondary field?

---

<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:** [May 25, 2018, 9:45am UTC](https://discuss.elastic.co/t/conditional-include-and-exclude-fields/129403/3 "2018-05-25T09:45:36Z")

</div>

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