# REST vs JAVA API

**URL:** <https://discuss.elastic.co/t/rest-vs-java-api/5761>\
**Category:** Elasticsearch\
**Created:** [November 3, 2011, 9:31am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761 "2011-11-03T09:31:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![achaayan](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@achaayan](https://discuss.elastic.co/u/achaayan)\
**Post date:** [November 3, 2011, 9:31am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/1 "2011-11-03T09:31:10Z")

</div>

We are building a Spring based application which will eventually reside in  
the cloud. I am confused if I should use REST or ES Java API to connect to  
my ES cluster. I am inclined towards using REST, because (1) the  
abstraction and flexibility which it provides (2) not sure how API will  
perform in cloud for discovering new nodes (3) client connection will be  
managed by Spring via RESTtemplate etc.I understand I will end up building  
JSON string to be sent over REST, but I feel it still is a better approach.  
Would greatly appreciate your thoughts on this. Thanks!!

---

<div class="post-metadata">

**Author:** ![Pavel\_Penchev](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Pavel\_Penchev](https://discuss.elastic.co/u/Pavel_Penchev)\
**Post date:** [November 3, 2011, 9:42am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/2 "2011-11-03T09:42:02Z")

</div>

One benefit of the Java API is that your client object is actually a  
node that joins the cluster. You get automatically the internal routing  
features and you don't have to handle joining/leaving of nodes.  
If your deployment model handles externally discovery and query/index  
routing then indeed the REST API may give you more flexibility.

Regards  
Pavel

On 3.11.2011 11:31, achaayan wrote:

> We are building a Spring based application which will eventually  
> reside in the cloud. I am confused if I should use REST or ES Java API  
> to connect to my ES cluster. I am inclined towards using REST, because  
> (1) the abstraction and flexibility which it provides (2) not sure how  
> API will perform in cloud for discovering new nodes (3) client  
> connection will be managed by Spring via RESTtemplate etc.I understand  
> I will end up building JSON string to be sent over REST, but I feel it  
> still is a better approach.  
> Would greatly appreciate your thoughts on this. Thanks!!

---

<div class="post-metadata">

**Author:** ![achaayan](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@achaayan](https://discuss.elastic.co/u/achaayan)\
**Post date:** [November 3, 2011, 9:53am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/3 "2011-11-03T09:53:05Z")

</div>

Thanks, Pavel.

Please correct me if I am wrong, but as per my understanding, the REST URL  
will be hitting a node, and as this node will be aware of any additional  
nodes joining / leaving the cluster. Hence, is there any benefits of using  
the Java client node API ?

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [November 3, 2011, 10:01am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/4 "2011-11-03T10:01:37Z")

</div>

Hi,

If you use Java client node API then your requests will be directly routed  
to the nodes that need to process your query, if you use REST over HTTP  
then your requests will be typically rerouted to other nodes. Also when  
using Java node client then the transport layer uses optimized protocol for  
node communication which again HTTP does not provide. This means that Java  
node client can provide you better performance. (Although I am not saying  
that the best performance is what you always need, sometimes it is better  
to prefer other options if they fits your overall system design).

Regards,  
Lukas

On Thu, Nov 3, 2011 at 10:53 AM, achaayan [felixmd@gmail.com](mailto:felixmd@gmail.com) wrote:

> Thanks, Pavel.
> 
> Please correct me if I am wrong, but as per my understanding, the REST URL  
> will be hitting a node, and as this node will be aware of any additional  
> nodes joining / leaving the cluster. Hence, is there any benefits of using  
> the Java client node API ?

---

<div class="post-metadata">

**Author:** ![achaayan](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@achaayan](https://discuss.elastic.co/u/achaayan)\
**Post date:** [November 3, 2011, 12:46pm UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/5 "2011-11-03T12:46:29Z")

</div>

Thanks !!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:49am UTC](https://discuss.elastic.co/t/rest-vs-java-api/5761/6 "2017-07-06T03:49:57Z")

</div>


