# How to design ES fields for nested logical query

**URL:** <https://discuss.elastic.co/t/how-to-design-es-fields-for-nested-logical-query/250978>\
**Category:** Elasticsearch\
**Created:** [October 5, 2020, 10:35am UTC](https://discuss.elastic.co/t/how-to-design-es-fields-for-nested-logical-query/250978 "2020-10-05T10:35:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ybc\_c](https://avatars.discourse-cdn.com/v4/letter/y/7feea3/32.png) [@ybc\_c](https://discuss.elastic.co/u/ybc_c)\
**Post date:** [October 5, 2020, 10:35am UTC](https://discuss.elastic.co/t/how-to-design-es-fields-for-nested-logical-query/250978/1 "2020-10-05T10:35:25Z")

</div>

I want to query ES to find docs meeting this pattern: A & (B | C) & (D | E). And A is the value of a field, both B and C are the values of the other field, and D and E are the values of another field.

Here is a concrete example:  
Gender: male, Birth Place: US, UK or JP, and Birth Day Range: 1990-1995, or 1996-2000

So a user profile of which gender is male, birth place is US and birth day range is 1990-1999 can be returned.  
And following user profiles will be ignored:

- gender: female, birth place is US and birth day range is 1990-1999 (gender part does not meet the condition)
- gender: male, birth place is CN and birth day range is 1990-1999 (birth place part is not one of US, UK or JP )
- gender: male, birth place is US and birth day range is 1980-1985 (birth day part is not one of 1990-1995 or 1996-2000)

what data type should I use? note that the number of these kinds of fields can be changed. Maybe later `Birth Day Range` is not considered any more. Or a new field called `Degree: BS, MS or PHD` can be added.

Note that ES 7.\* is used.

Thanks

---

<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:** [November 2, 2020, 10:35am UTC](https://discuss.elastic.co/t/how-to-design-es-fields-for-nested-logical-query/250978/2 "2020-11-02T10:35:40Z")

</div>

Closed on November 2, 2020, 10:35am UTC

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