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).;
Xarouma
  • 171
  • 1
  • 10

1 Answers1

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

sven.kwiotek
  • 1,459
  • 15
  • 22
  • 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 – Xarouma Dec 10 '14 at 07:14