简体   繁体   中英

Elasticsearch Query Aggregate spring framework elasticsearsh How To?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM