Elastic Search Java AND Text Query

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();

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

What do you mean?
With the code you provided, you need to satisfy both conditions. So it is to me somehow a AND query, right?

On a side note, prefer using matchQuery instead of textQuery (deprecated).

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 9 juil. 2013 à 14:35, fegeilert@googlemail.com a écrit :

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();

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.