I use
ElasticSearchTemplate().queryForPage(SearchQuery, CLASS)
How can I print the full json request?
I manage to print only filter by doing :
searchQuery.getFilter().toString()
But cant manage to do the same with:
 searchQuery.getAggregations().toString();
I would like to print in console something like :
 "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
             }
           }
         }
       }
     }
   }
 }
                This is what I've started using to do the same thing.
{
  "top_agg": {
    "terms": {
      "field": "id",
      "size": 100
    },
    "aggregations": {
      "parent": {
        "nested": {
          "path": "transactions"
        },
        "aggregations": {
          "totals": {
            "filter": {
              "terms": {
                "transactions.type": [
                  "ttype"
                ]
              }
            },
            "total_events": {
              "cardinality": {
                "field": "parent.field"
              }
            }
          }
        }
      }
    }
  }
}
NativeSearchQuery query = queryBuilder.build();
if (query.getQuery() != null) {
    log.debug(query.getQuery().toString());
}
if (query.getAggregations() != null) {
    try {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject();
        for (AbstractAggregationBuilder subAgg : query.getAggregations()) {
            subAgg.toXContent(builder, ToXContent.EMPTY_PARAMS);
        }
        builder.endObject();
        log.debug(builder.string());
    } catch (IOException e) {
        log.debug("Error parsing aggs");
    }
}
                        Could you use the SearchResponse.getAggregations().asList() ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With