Dear Elasticsearch Community,
currently trying to solve an use-case of a reverse AND condition on user search queries where all tokens have to be included in an indexed field in order to match a certain document.
Example:
Indexed documents have a property field with multiple tokens.
"fieldXyz" : "quick brown fox"
The search should now only match if the user includes ALL tokens in his search request but the order should not matter.
So basically the following should NOT match:
"quick"
"quick brown"
"quick fox"
...
However these should match:
"brown quick fox"
"fox quick brown"
...
I was thinking about counting the number of tokens via token_count and adding another field on index time. However there is still the challenge of counting the tokens after analysis on query time (since stopwords and so on should be not counted). We cannot do this when processing the query on application level since the query is not analysed yet and calling the analyse API would create an additional round trip and increasing the search response time.
So is there a way to return the token count from maybe a custom analyzer and then match it to the field including the token count?