Multiple Exact searches


(Malini) #1

I want to execute multiple exact searches along with AND/OR operator.
For example search exact searche for "cloud computing" AND "cloud security".
What kind of query to use?

I am trying the following java api which is not working. Any suggestions would be appreciated.
srb = client.prepareSearch("index1");
QueryBuilder qb1 = (QueryBuilder) QueryBuilders.queryString("""+ searchText1+ """).field("content");
QueryBuilder qb2 = (QueryBuilder) QueryBuilders.queryString("""+ searchText2+ """).field("content");
qb = boolQuery.should(qb1).should(qb2);
srb.setQuery((org.elasticsearch.index.query.QueryBuilder) qb);

SearchResponse functionResponse = srb.setFrom(searchStart).setSize(searchForm.getResultsPerPage()).execute().actionGet();


(Michael McCandless) #2

If both of your sub-queries (the phrase queries) are required then you should use boolQuery.must instead of boolQuery.should?


(Malini) #3

I modified to queryString since i need to search from more than one fields. This works. Thanks for your response.

QueryBuilder qb1 = (QueryBuilder) QueryBuilders.queryString("""+ searchText1+ """).field("content").field("titlefield.title");
QueryBuilder qb2 = (QueryBuilder) QueryBuilders.queryString("""+ searchText2+ """).field("content").field("titlefield.tile");
qb = boolQuery.must(qb1).must(qb2);


(Malini) #4

I want to have "OR" and "NOT" query. I want to search for searchtext1 or serachtest2 from multiple fields. How can I achieve this?


(system) #5