# Create a conditional mapping (enabled = false) on a single field based on field value

**URL:** <https://discuss.elastic.co/t/create-a-conditional-mapping-enabled-false-on-a-single-field-based-on-field-value/317572>\
**Category:** Elasticsearch\
**Created:** [October 27, 2022, 2:01am UTC](https://discuss.elastic.co/t/create-a-conditional-mapping-enabled-false-on-a-single-field-based-on-field-value/317572 "2022-10-27T02:01:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JerryKumar](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@JerryKumar](https://discuss.elastic.co/u/JerryKumar)\
**Post date:** [October 27, 2022, 2:01am UTC](https://discuss.elastic.co/t/create-a-conditional-mapping-enabled-false-on-a-single-field-based-on-field-value/317572/1 "2022-10-27T02:01:07Z")

</div>

Hey team,

I have a use case in my application where a list of items called Descriptors are generated. These are filtered for a specific prefix "descsearch" and only these are being sent to the index and everything worked fine.

However due to a business change we now want ALL descriptors to be sent to the index to be returned by searches, (though the "descsearch" prefixed ones should be the only searchable ones).

When I make this change I am running into a mapping explosion issue because all of the NON prefixed descriptors are dynamically generated. Raising the mapping limit does not solve this issue and is causing other issues.

Type: mapper\_parsing\_exception Reason: "failed to parse" CausedBy: "Type: illegal\_argument\_exception Reason: "Limit of total fields [2000] has been exceeded while adding new fields [2]"

The solution I am trying to implement is to only have the "descsearch" prefixed descriptors to be searchable (enabled = true) and I don't want ES to worry about mapping any of the other descriptors (set them to enabled = false).

In other words, on my descriptors field, I want to introduce a conditional that checks if the item has the prefix, and if it does we want enabled = true, otherwise we want enabled = false.

Is there any way to achieve this using only one field or does there need to be two separate fields?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 27, 2022, 5:57am UTC](https://discuss.elastic.co/t/create-a-conditional-mapping-enabled-false-on-a-single-field-based-on-field-value/317572/2 "2022-10-27T05:57:24Z")

</div>

If you only want fields whose names start with `descsearch` to be searchable and all other fields to not be indexed you can use an index template to specify this.

---

<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 24, 2022, 5:57am UTC](https://discuss.elastic.co/t/create-a-conditional-mapping-enabled-false-on-a-single-field-based-on-field-value/317572/3 "2022-11-24T05:57:49Z")

</div>

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