It would be good if you could show what you tried with the BoolQuery
and explain why it didn't work. Here is an example of your query using the Java API's BoolQuery
.
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.should(QueryBuilders.termsQuery("lang", "en"));
boolQuery.should(QueryBuilders.termsQuery("location", "en"));
BoolQueryBuilder titleBoolQuery = QueryBuilders.boolQuery();
titleBoolQuery.should(QueryBuilders.termsQuery("title", new String[]{"americanlegion", "conversion"}));
titleBoolQuery.must(QueryBuilders.termQuery("title", "conversion"));
boolQuery.should(titleBoolQuery);
Resulting JSON:
{
"bool" : {
"should" : [ {
"terms" : {
"lang" : [ "en" ]
}
},{
"terms" : {
"location" : [ "pa" ]
}
},{
"bool" : {
"must" : {
"term" : {
"title" : "conversion"
}
},
"should" : {
"terms" : {
"title" : [ "americanlegion", "conversion" ]
}
}
}
} ]
}
}
EDIT
If you want to use the Lucene syntax use the QueryStringQueryBuilder
QueryStringQueryBuilder query = QueryBuilders.queryString("user.name:\"John\" OR user.name:\"Matt\"");
this will produce the JSON
{
"query_string" : {
"query" : "user.name:\"John\" OR user.name:\"Matt\""
}
}