Hello,
I am currently working on a project using elastic search.
The code for this project is written in java.
My problem is the following:
I want to create two text (sub-)queries in one query using
a Boolean query. However the two queries are always
combined using a logical OR function. Is there a way to
combine the queries using AND?
The current code looks somewhat like the following:
SearchResponse response = client.prepareSearch("myindex")
.setTypes("mymapping")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.textQuery("field1", "value1"))
.must(QueryBuilders.textQuery("field2", "value2")))
.setFrom(start).setSize(offset)
.addField("field1")
.addField("field2")
.execute()
.actionGet();
Hello,
I am currently working on a project using Elasticsearch.
The code for this project is written in java.
My problem is the following:
I want to create two text (sub-)queries in one query using
a Boolean query. However the two queries are always
combined using a logical OR function. Is there a way to
combine the queries using AND?
The current code looks somewhat like the following:
SearchResponse response = client.prepareSearch("myindex")
.setTypes("mymapping")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.textQuery("field1", "value1"))
.must(QueryBuilders.textQuery("field2", "value2")))
.setFrom(start).setSize(offset)
.addField("field1")
.addField("field2")
.execute()
.actionGet();
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.