在Java API-SearchQuery中打印完整的json请求

时间:2015-12-15 14:19:54

标签: elasticsearch

我在下面写了使用搜索查询API的方法并想要打印完整的json请求?

            SearchQuery searchQuery = new NativeSearchQueryBuilder()
                        .withIndices("players").withTypes("player")
                        .withFilter(FilterBuilders.termsFilter("_id", "player1")).addAggregation(AggregationBuilders.filter("playerFilterAggs")
                        .filter(FilterBuilders.termsFilter("_id", "player1"))
                        .subAggregation(terms("playerAggs")
                        .field("player"))).build();
                        System.out.println(searchQuery);

我设法通过执行以下操作仅打印过滤器:     searchQuery.getFilter()。的toString()

But cant manage to do the same with:

     searchQuery.getAggregations().toString();
    I would like to print in console something like this :

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

0 个答案:

没有答案