2

I am using Elasticsearch and I need to do a phrase_search with the first term matching as regex. To be more precise: I need to search over the string that has this patter:

"(number) msec".

I know that there is the "regexp" query type, but that allows me to search only for just one term. Using two boolean clauses would not work too, since It would be irrespective of the sequence.

Instead, I would like to use the "regexp" operator somehow nested inside the phrase query, in order to have a match in the exact sequence.

Does anybody know how to do it?

1 Answer 1

3

Regexp query on analyzed (tokenized) field can only be applied to a term, so you can not do multi-word regexp queries. You need to have not analyzed (for example with type keyword) ES field in your mapping, that will allow you to match regexp to the whole phrase, and not just terms.

Sign up to request clarification or add additional context in comments.

2 Comments

Im new to Elasticsearch and im trying to understand exactly this - how or if proximity operator can be used with two or more regex pattern matching statements (e.g for two or more words and their plurals or misspellings within x word positions of each other). The regex pattern matching is how all of the users are trained to search and important to the users. If there is no other way we may have to build a query through an interface that translates it to permutations of spellings consisting of multiple proximity searches without regex.
@JayC.Besch I do not think there is a simple way to run regex on a full non-tokenized value of the field out of the box. You can surely do that by using script field and matching raw data on regex in your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.