0

我想使用以下方法聚合我的查询结果:

  "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
              }
            }
          }
        }
      }
    }
  }

我如何在 java 中使用 elasticsearch spring 框架来做到这一点?我该调用哪种方法?在哪个物体上?

到目前为止,这是我在 java 中的代码:

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

    searchQueryNative.
    SearchQuery searchQuery = searchQueryNative.build();

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

1 回答 1

1

当您使用:

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

你可以利用:

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

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

于 2014-12-09T15:42:41.287 回答