# Dynamic custom fields with numeric and date range queries

**URL:** <https://discuss.elastic.co/t/dynamic-custom-fields-with-numeric-and-date-range-queries/277574>\
**Category:** Elasticsearch\
**Created:** [July 1, 2021, 3:14pm UTC](https://discuss.elastic.co/t/dynamic-custom-fields-with-numeric-and-date-range-queries/277574 "2021-07-01T15:14:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbiondic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nbiondic/32/85045_2.png) [@nbiondic](https://discuss.elastic.co/u/nbiondic)\
**Post date:** [July 1, 2021, 3:14pm UTC](https://discuss.elastic.co/t/dynamic-custom-fields-with-numeric-and-date-range-queries/277574/1 "2021-07-01T15:14:51Z")

</div>

We have a requirement to support custom search fields for our users. Each user should have an ability to create their own fields which can than be searched through by using our built-in filtering mechanism

Our initial idea was to store each custom field as an object in an array stored in flattened type property of the document. That way we would define an object that has type, key and value and use standard filter operators.  
The problem arises when we want to have number and date fields and filter on them, because flattened type doesn't support all the query operators and it doesn't seem to behave as we would expect it to. Is there a way we can use range queries properly on number and date fields of flattened property?  
Is there perhaps another way we could get the desired functionality of each customer being able to define custom fields and filter on them?

One idea was having a separate index per customer, but we would like to avoid that.  
Another is using the old nested type property, however that increases index size significantly.

Ideally we want to support operations like **greater than** , **lower than** and **between** on number and date fields, and **starts with** , **ends with** and **contains** on string fields.

---

<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 29, 2021, 3:15pm UTC](https://discuss.elastic.co/t/dynamic-custom-fields-with-numeric-and-date-range-queries/277574/2 "2021-07-29T15:15:10Z")

</div>

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