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

Hello,

let's assume my index looks like the following:

"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!

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

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