I am not getting how to use SearchResponse in Aggregation


(Gourav Bhattacharya) #1

Here one client method creating problem for me. I went through java api of elastic search but still not getting that client() usage and node usage.
Please help me out.

Here is the syntax.
SearchResponse sr = node.client().prepareSearch()
.addAggregation(
AggregationBuilders.terms("by_country").field("country")
.subAggregation(AggregationBuilders.dateHistogram("by_year")
.field("dateOfBirth")
.dateHistogramInterval(DateHistogramInterval.YEAR)
.subAggregation(AggregationBuilders.avg("avg_children").field("children"))
)
)
.execute().actionGet();


(David Pilato) #2

I'd use the REST client: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html


(Gourav Bhattacharya) #3

Thank you, I also want to import some JSON file through rest client using bulk API. Unfortunately, I'm unable to do, could you please show me the syntax or something related to it that I can do it.


(David Pilato) #4

This?

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.