英文:
Using java, how to change the default operator of match query to AND in elasticsearch?
问题
当使用以下的Java API时:
query.must(matchQuery("name", object.getName()));
生成的Elasticsearch查询为:
"bool":{
"must":[
{"match":{"name":{"query":"De Michael Schuster","operator":"OR","boost":1.0}}}
.....
目前我得到的文档名称为:De OR Michael OR Schuster,正如预期的那样。
我想将操作符更改为AND,以匹配整个字符串。
我知道我可以使用term查询,但在我的情况下这不是一个选项。
我找到了这个帖子,但是没有给出答案 - https://discuss.elastic.co/t/changing-the-default-operator-for-search-api/47033
请问如何在Java中实现这一点?
英文:
When using java api as below
query.must(matchQuery("name", object.getName()));
The resulted elastic query is
"bool":{
"must":[
{"match":{"name":{"query":"De Michael Schuster","operator":"OR","boost":1.0}}}
.....
Right now I am getting back document with name : De OR Michael OR Schuster as expected.
I want to change the operator to AND to match the whole string.
I know I can use term query, but that is not an option in my scenario.
I came across this, but the answer is not given - https://discuss.elastic.co/t/changing-the-default-operator-for-search-api/47033
How can I achieve this using Java ?
答案1
得分: 0
仅仅像这样:
query.must(matchQuery("name", object.getName()).operator(Operator.AND));
英文:
Simply like this:
query.must(matchQuery("name", object.getName()).operator(Operator.AND));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论