# Java API Client And Node

**URL:** <https://discuss.elastic.co/t/java-api-client-and-node/8085>\
**Category:** Elasticsearch\
**Created:** [June 13, 2012, 4:55pm UTC](https://discuss.elastic.co/t/java-api-client-and-node/8085 "2012-06-13T16:55:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samCougars](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@samCougars](https://discuss.elastic.co/u/samCougars)\
**Post date:** [June 13, 2012, 4:55pm UTC](https://discuss.elastic.co/t/java-api-client-and-node/8085/1 "2012-06-13T16:55:46Z")

</div>

I'm using JAVA API.  
When I'm indexing document, I create a node by setting properties and close it as follow:  
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();  
settings.put("path.home","elasticSearchNode");  
settings.put("number\_of\_shards",1);  
settings.put("number\_of\_replicas",0);

Node node = NodeBuilder.nodeBuilder().settings(settings).clusterName(elasticSearchNode).node();  
node .close();

But when I'm doing search, I get the node as follows :  
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();  
settings.put("path.home","elasticSearchNode");  
Node node = NodeBuilder.nodeBuilder().settings(settings).clusterName(elasticSearchNode).node();

But, I'm not closing this node because when a next search request comes to, it uses the same node.

Is it bad to leave the node open for next request? What are the downsides of my approach?  
Thanks

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 13, 2012, 5:36pm UTC](https://discuss.elastic.co/t/java-api-client-and-node/8085/2 "2012-06-13T17:36:24Z")

</div>

On Jun 13, 9:55 am, samCougars [sban...@gmail.com](mailto:sban...@gmail.com) wrote:

> Is it bad to leave the node open for next request? What are the downsides of  
> my approach?

Nodes (and Clients) are expensive to create, and I'm not aware of any  
reasons to create more than one instance each per application.

---

<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:24am UTC](https://discuss.elastic.co/t/java-api-client-and-node/8085/3 "2017-07-06T03:24:33Z")

</div>


