I am using ES 1.5.2 both on client and server. Following query works fine when run from REST call manually:
{
"size" : 0,
"aggregations" : {
"favorite" : {
"filter" : {
"and" : {
"filters" : [ {
"term" : {
"favorites.details" : 52891
}
}, {
"term" : {
"_type" : "favorites"
}
} ]
}
}
}
}
}
but failes when run from JAVA api with error:
nested: SearchParseException[[app16389900_at_heroku_com_bloom-v2][0]: from[-1],size[0]: Parse Failure [No parser for element [aggregations]]]; }]
Can anybody help pleasE?
UPDATE: Java code:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
List<String> indexTypes = Lists.newArrayList();
for (String action : actions) {
FilterAggregationBuilder aggr = null;
if (RATING_ACTION.equals(action)) {
TermFilterBuilder term =
FilterBuilders.termFilter(INDEX_TYPES.get(action)
+ ".details.user_id", userId);
aggr = new FilterAggregationBuilder(action).filter(term);
indexTypes.add(INDEX_TYPES.get(action));
} else if (COMMENTS_ACTION.equals(action)) {
TermFilterBuilder term = FilterBuilders.termFilter(COMMENTS_TYPE
+ ".user_id", userId);
aggr = new FilterAggregationBuilder(action).filter(term);
indexTypes.add(COMMENTS_TYPE);
} else if (CREATED_ACTION.equals(action)) {
TermFilterBuilder term =
FilterBuilders.termFilter("activities.created_by", userId);
aggr = new FilterAggregationBuilder(action).filter(term);
indexTypes.add(ACTIVITIES_TYPE);
} else {
TermFilterBuilder term =
FilterBuilders.termFilter(INDEX_TYPES.get(action) + ".details",
userId);
TermFilterBuilder type = FilterBuilders.termFilter("_type",
INDEX_TYPES.get(action));
AndFilterBuilder filter = FilterBuilders.andFilter(term, type);
aggr = new FilterAggregationBuilder(action).filter(filter);
indexTypes.add(INDEX_TYPES.get(action));
}
searchSourceBuilder.aggregation(aggr);
}
searchSourceBuilder.size(0);
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(
INDEX).setSearchType(SearchType.COUNT).addType(
indexTypes).build();
JestResult result = client.execute(search);