Setting aggregations on SearchTemplateRequestBuilder (ES 5.1.2)


#1

Hi,

I just stumbled upon a problem during migration to ES 5.1.2 from ES 1.6. We are using the transport client API and leverage aggregations that are added to several of our template based queries.

This worked as expected on ES 1.6, we build the aggregations dynamically in java and use them together with template based queries. Is there any way of doing this using the ES 5.1.2 transport client? That is without moving the aggregations to all of our search templates? As a side note the "from" and "to" fields are also ignored, and it seems like these have to be explicitly set in each template and passed as parameters.

            SearchRequestBuilder builder = esClient.prepareSearch(xx)
                .setTypes(xx)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setFrom(xx)
                .setSize(xx)
                .setTrackScores(true);
          ..
          for (AbstractAggregationBuilder aggregation : aggregationBuilders) {
                builder.addAggregation(aggregation);
          }
         ..
         .. if template based query
          SearchTemplateRequestBuilder templateBuilder = new SearchTemplateRequestBuilder(esClient)
                    .setRequest(builder.request())
                    .setScript(templateName)
                    .setScriptType(ScriptType.FILE)
                    .setScriptParams(templateParams);

       ..
      response = templateBuilder.get

     The response have no aggregations.

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.