# Determine search fields dynamically based on user input - native Elastic solution?

**URL:** <https://discuss.elastic.co/t/determine-search-fields-dynamically-based-on-user-input-native-elastic-solution/309711>\
**Category:** Elasticsearch\
**Created:** [July 15, 2022, 7:30am UTC](https://discuss.elastic.co/t/determine-search-fields-dynamically-based-on-user-input-native-elastic-solution/309711 "2022-07-15T07:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seb.sch](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@seb.sch](https://discuss.elastic.co/u/seb.sch)\
**Post date:** [July 15, 2022, 7:30am UTC](https://discuss.elastic.co/t/determine-search-fields-dynamically-based-on-user-input-native-elastic-solution/309711/1 "2022-07-15T07:30:43Z")

</div>

Hello,

let's assume my index looks like the following:

```auto
"mappings" : {
  "properties" : {
	"id" : {
	  "type" : "text"
	},
	"mail" : {
	  "type" : "text"
	},
	"fullName" : {
	  "type" : "text"
	},
	"dateOfBirth" : {
	  "type" : "text"
	}
  }
}

```

Now, I would like to search in certain fields only, if the search string (from user input) matches a certain (regex) pattern, i.e.:

- A[0-9]{5}: search only in field "id"
- /@/: search only in field "mail"
- [a-zA-Z]+\s[a-zA-Z]+: search only in field "fullName"
- (0?[1-9]|[12][0-9]|3[01]).(0?[1-9]|[1][0-2]).[0-9]{4}: search only in field "dateOfBirth"
- if nothing matches: search in all fields

Of course, I could do that programmatically by pattern matching before sending the query to Elastic, but I'd like to know whether there's a built-in functionality of Elastic that I'm missing out here.

Any advice is appreciated!

---

<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:** [July 15, 2022, 7:37am UTC](https://discuss.elastic.co/t/determine-search-fields-dynamically-based-on-user-input-native-elastic-solution/309711/2 "2022-07-15T07:37:43Z")

</div>

There is nothing like that in Elasticsearch, so you will need to do it when creating the query.

---

<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 12, 2022, 7:38am UTC](https://discuss.elastic.co/t/determine-search-fields-dynamically-based-on-user-input-native-elastic-solution/309711/3 "2022-08-12T07:38:26Z")

</div>

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