0

I would like to aggregate the result of my query using the following :

  "aggs": {
"agg1": {
      "terms": {
        "field": "basket_id_1",
        "size":0
      },
      "aggs": {
        "basket_id_2": {
          "terms": {
            "field": "basket_id_2",
            "size":0
          },
          "aggs": {
            "basket_id_3": {
              "terms": {
                "field": "basket_id_3",
                "size":0
              }
            }
          }
        }
      }
    }
  }

How do I do that in java, using elasticsearch spring framework ? Which method do I call ? and on which object ?

here is my code in java so far :

       NativeSearchQueryBuilder searchQueryNative = new NativeSearchQueryBuilder()
            .withIndices(this.getIndex()).withTypes(this.getType());

    searchQueryNative.
    SearchQuery searchQuery = searchQueryNative.build();

    Page<Object> result = this.getElasticsearchTemplate().queryForPage(
            searchQuery, Object.class).;

1 Answer 1

1

When you work with:

@Bean
public Client client() {
    return nodeBuilder().settings(buildNodeSettings()).node().client();
}

you could make use of:

client().prepareSearch()
    .setQuery( /* your query */ )
    .addAggregation( /* add an aggregation */ )
    .execute().actionGet();

see http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/java-aggs.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, Ive seen that, and it hasnt been working so far, but then the library i was using was too old and didnt have aggregation implemented (Only facets). Thats why it wasnt working with the aggregation. Thank you for your answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.