Maintain sequence order for match phrase query with slop in Elasticsearch Java API

1.8k Views Asked by At

I am trying to do a query which should be similar to the phrase query except that there can be gaps within consecutive tokens. Example:

Document: "a b c d"
Search: "a c" >> This should return the document,
Search: "c a" >> This should not return the document.

Phrase query ensures that the order will remain only when no slop value is being used. Once I add some slop value (2, 3 etc), it starts to break order, and with sufficiently large slop value, it will probably just be as normal match query as mentioned in elasticsearch documentation.

Note, I am using the AND operator, hence all the search tokens must be present.

Is it possible to do queries like this in Elasticsearch?

[EDIT] As for being marked as duplicate to this question, I am using spring-data-elasticsearch for my project and the stack overflow question does not have an answer that is related to spring-data elasticsearch java-api (ElasticsearchTemplate preferably).

0

There are 0 best solutions below