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

血红的双手。 提交于 2019-12-11 10:41:50

问题


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).

来源:https://stackoverflow.com/questions/35323657/maintain-sequence-order-for-match-phrase-query-with-slop-in-elasticsearch-java-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!