0

I need to fetch the number of matched data from ElasticSearch using REST API. Currently I am using elasticsearch-6.4.0.jar to write API. Unfortunately I could not find CountAPI in this version.

Moreover I tried to use older version jar (elasticsearch-2.4.0.jar). There I could see CountRequest & CountResponse classes. This class help us to fetch the Count.

CountRequest countRequest = new CountRequest(); 
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
searchSourceBuilder.query(QueryBuilders.matchAllQuery()); 
countRequest.source(searchSourceBuilder);

However 2.4.0 is very older version. Hence could you please help me to find deprecated version in elasticsearch-6.4.0.jar

HShetty
  • 21
  • 2
  • 7

1 Answers1

0

If you meant that you are using the Java High Level Rest Client 6.4, the count was added to it only in v6.6 release. https://github.com/elastic/elasticsearch/pull/34267

The one in 2.4 is based out of Transport client which has been deprecated from 7.0. Elastic recommends to use the HLRC which the I think you are already doing.

HLRC was feature complete with support for all APIs only in 7.0. Since version of client HLRC is tightly dependent on your cluster version you may be restricted, but if possible try to update to >=6.6 version of the library.

If you cannot update your driver version, the option I can think of is

  • to call through LLRC (RestClient class) (without support for Object builders)
  • or go back and use the Transport Client approach

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.6/java-rest-high-compatibility.html#java-rest-high-compatibility

The High Level Client is guaranteed to be able to communicate with any Elasticsearch node running on the same major version and greater or equal minor version. It doesn’t need to be in the same minor version as the Elasticsearch nodes it communicates with, as it is forward compatible meaning that it supports communicating with later versions of Elasticsearch than the one it was developed for.

The 6.0 client is able to communicate with any 6.x Elasticsearch node, while the 6.1 client is for sure able to communicate with 6.1, 6.2 and any later 6.x version, but there may be incompatibility issues when communicating with a previous Elasticsearch node version, for instance between 6.1 and 6.0, in case the 6.1 client supports new request body fields for some APIs that are not known by the 6.0 node(s).

pkp9999
  • 159
  • 4
  • Thanks for the quick reply. :) Right now I am using elasticsearch-rest-high-level-client-6.4.0.jar & elasticsearch-6.4.0.jar You meant to say that, I need to use elasticsearch-rest-high-level-client-6.6.0.jar or above version as well as elasticsearch-6.6.0.jar or above version to achieve CountAPI? If yes, could you please let me know the class name. That would be great. As I said, in the older version I could see below class being used for Count API. elasticsearch-6.4.0.jar\org\elasticsearch\action\count\CountRequest.java – HShetty Apr 20 '20 at 13:20
  • Yes. I havent explicitly used that API from HLRC myself. But you can find out the exact class from the files Changes in that PR link I shared. This documentation should help as well https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.6/java-rest-high-count.html – pkp9999 Apr 20 '20 at 13:50
  • Thank you :) Will try – HShetty Apr 21 '20 at 15:13