I am trying to use Java api within Eclipse in order to aggregate my data in Elasticsearch.
I successfully created a client to access my elasticsearch. Now, I want to do aggregations, that's why i followed this tutorial https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-aggs.html
SearchResponse sr = node.client().prepareSearch()
.setQuery( /* your query / )
.addAggregation( / add an aggregation */ )
.execute().actionGet();
However, it does not indicate how to initialize the variable 'node'. I put:
Node node = NodeBuilder.nodeBuilder().node();
SearchResponse sr = node.client().prepareSearch()
.setQuery( /* your query / )
.addAggregation( / add an aggregation */ )
.execute().actionGet();
But, I get the error: The method prepareSearch(String[]) in the type Client is not applicable for the
arguments ()
Actually, i have no problem to create my client.. I used the following code:
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(serverIpAddr), 9300));
//.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(serverIpAddr), 9300));
Thank you Nicolas, I used what you gave me:
here is what I did for those who will encounter the same problem.
String[] index= new String[1];
index[0]="myIndex";
//aggregate
SearchResponse response1 = (SearchResponse) client.prepareSearch(myIndex)
.execute()
.actionGet();
System.out.println(response1);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.