Aggregations issue


(Cristi Boariu) #1

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

(Ramy) #2

Where is the path for nested filed? if you use nested fields, you need to define the path of it!
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html


(Colin Goodheart-Smithe) #3

Can you show how you are calling this from the JAVA API?


(Cristi Boariu) #4

Added java code.


(Colin Goodheart-Smithe) #5

I can't see anything obvious from the code (although I don;t have any experience with JEST only with the Elasticsearch Java client). Would you be able to paste (maybe into a gist if the output is long) the output of searchSourceBuilder.toString() just before you create the search variable? Also, see if you can run the output of this call using cURL or similar.


(Cristi Boariu) #6

@colings86 I have added some logging so here's the output of searchSourceBuilder.toString():

--SEARCH SOURCE BUILDER:

{
  "size" : 0,
  "aggregations" : {
    "favorite" : {
      "filter" : {
        "and" : {
          "filters" : [ {
            "term" : {
              "favorites.details" : 50391
            }
          }, {
            "term" : {
              "_type" : "favorites"
            }
          } ]
        }
      }
    }
  }
}

and the error is the same I posted in original post. As I said, if I try with curl or Postman it works so its something on java side not knowing to parse the source because of aggregations....


(Colin Goodheart-Smithe) #7

I can't see anything wrong with that JSON. Maybe there is something peculiar about how JEST is creating the search request. I can only suggest either using something like wireshark to intercept the actual HTTP request that is sent to the server and see how it is different (if it is different), or maybe try this in the Elasticsearch Java Client.


(system) #8