英文:
Elasticsearch multiple query values
问题
你好,我正在尝试使用Elasticsearch创建一个查询:
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.5.3</version>
</dependency>
我需要查询以多个值为基础选择多个文件:
query = MatchQuery.of(m -> m
.field("fileType")
.query("EXP", "WAIT_EXP")
)._toQuery();
但这给我一个语法错误。查询只获取1个值。我需要获取fileType为exp或wait_exp的文件。
我阅读了这里的文档 https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html,但找不到有用的信息。
英文:
Hi I am trying to create a query with elastic search :
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.5.3</version>
</dependency>
I need the query to select multiple files based on values:
query = MatchQuery.of(m -> m
.field("fileType")
.query("EXP", "WAIT_EXP")
)._toQuery();
But this is giving me an syntax error. The query only gets 1 value. I need the get files with fileType both exp or wait_exp.
I read the documentation at here https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html but cant find anything helpfull.
答案1
得分: 1
你可以使用布尔查询(bool query)。此外,你可以查看这个线程。
SearchRequest request = new SearchRequest("your_index");
BoolQuery boolQuery = new BoolQuery();
boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("EXP")));
boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("WAIT_EXP")));
request.query(boolQuery);
英文:
You can use bool query. Also you can check this thread.
SearchRequest request = new SearchRequest("your_index");
BoolQuery boolQuery = new BoolQuery();
boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("EXP")));
boolQuery.should(MatchQuery.of(m -> m.field("fileType").query("WAIT_EXP")));
request.query(boolQuery);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论