Hey everybody,
during my experiments with elasticsearch I've found differing behaviour
using the Java-API-Builders for BoolFilters and BoolQueries.
When I try to add multiple must clauses to both of them, the BooleanQuery
seemingly works correct in merging multiple must-terms into an array, eg:
final SearchRequestBuilder s = client.prepareSearch();
s.setQuery(boolQuery().must(termQuery("f1",
"v1")).must(termQuery("f2", "v2")));
s.toString returns:
{
"query" : {
"bool" : {
"must" : [ {
"term" : {
"f1" : "v1"
}
}, {
"term" : {
"f2" : "v2"
}
} ]
}
}
}
But, when I try to do the equivalent for a BooleanFilter, multiple
must-terms collide and only one of them is preserved in the
Json-representation, eg:
final SearchRequestBuilder s = client.prepareSearch();
s.setQuery(constantScoreQuery(boolFilter().must(termFilter("f1",
"v1")).must(termFilter("f2", "v2"))));
s.toString returns:
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : {
"term" : {
"f1" : "v1"
}
},
"must" : {
"term" : {
"f2" : "v2"
}
}
}
}
}
}
}
Here both must-Terms within the Hash collide.
Checking the source, I found that the implementation of both classes differ
substantially, so that I suspect there is a misunderstanding on my side.
Any help is highly appreciated!
Thank you very much.
Björn Hachmann