# Need help with client node creation spring on localhost :(

**URL:** <https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810>\
**Category:** Elasticsearch\
**Created:** [November 8, 2011, 12:38pm UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810 "2011-11-08T12:38:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![steam](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@steam](https://discuss.elastic.co/u/steam)\
**Post date:** [November 8, 2011, 12:38pm UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/1 "2011-11-08T12:38:24Z")

</div>

Hello,  
I make intent to reuse class ElasticsearchNodeFactoryBean from article 'Elasticsearch with Spring'  
([http://techo-ecco.com/blog/elasticsearch-with-spring/](http://techo-ecco.com/blog/elasticsearch-with-spring/)).

I have a problem with client node creation on localhost.  
Can you help me please.

I start elasticsearch.bat from elastic folder, to create server node to store in it the indexes.  
Then i start a client node from my java main class with spring configuration and want recover indexes from server node.  
I was changed a little ElasticSearchNodeFactoryBean because node was not recognized with master server node  
(that created with elasticsearch.bat and named like MasterNode).  
Both nodes works on localhost and with same jdk1.6 and elasticsearch-0.18.2

My snippets code and logs with my comments:

Spring applicationContext.xml

```
<bean id="searchNode" class="com.web.project.elasticsearch.ElasticSearchNodeFactoryBean">
    <property name="configLocation" value="classpath:/spring/elasticsearch.properties"/>
</bean>

<bean id="searchClient" factory-bean="searchNode" factory-method="client" />
<bean id="adminClient" factory-bean="searchClient" factory-method="admin" />

```

elasticsearch.properties

```
node.name=MyNode
node.client=true
node.local=true
node.data=false
index.number_of_shards=3
index.store.fs.memory.enabled=false
index.analysis.analyzer.projectx_standard.type=standard
index.analysis.analyzer.projectx_standard.filter=[lowercase]

```

And code to get index:

```
    ClassPathXmlApplicationContext ctx = 
    	new ClassPathXmlApplicationContext("classpath:/spring/applicationContext.xml");
    
    Client client = (Client) ctx.getBean("searchClient");
	
	GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .execute()
        .actionGet();
    	        
    System.out.println("End get ..."+response.sourceAsString());

```

When I run test on server node (MasterNode) i have a lot of exeptions:

java.io.IOException: Se ha forzado la interrupci¾n de una conexi¾n existente por  
el host remoto  
at sun.nio.ch.SocketDispatcher.read0(Native Method)  
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)  
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)  
at sun.nio.ch.IOUtil.read(IOUtil.java:200)  
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioW  
orker.java:321)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSe  
lectedKeys(NioWorker.java:280)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWo  
rker.java:200)  
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(Thread  
RenamingRunnable.java:108)  
at [org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru](http://org.elasticsearch.common.netty.util.internal.DeadLockProofWorker%241.ru)  
n(DeadLockProofWorker.java:44)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec  
utor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor  
.java:908)  
at java.lang.Thread.run(Thread.java:619)  
[2011-11-08 13:01:45,311][WARN][transport.netty] [MasterNode] Excepti  
on caught on netty layer [[id: 0x01c8f59c, /192.168.4.161:4421 =\> /192.168.4.161  
:9300]]  
java.io.IOException: Se ha forzado la interrupci¾n de una conexi¾n existente por  
el host remoto  
at sun.nio.ch.SocketDispatcher.read0(Native Method)  
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)  
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)  
at sun.nio.ch.IOUtil.read(IOUtil.java:200)  
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioW  
orker.java:321)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSe  
lectedKeys(NioWorker.java:280)  
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWo  
rker.java:200)  
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(Thread  
RenamingRunnable.java:108)  
at [org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru](http://org.elasticsearch.common.netty.util.internal.DeadLockProofWorker%241.ru)  
n(DeadLockProofWorker.java:44)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec  
utor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor  
.java:908)  
at java.lang.Thread.run(Thread.java:619)  
[2011-11-08 13:01:46,108][INFO][cluster.service] [MasterNode] removed  
{[Aguja][RHkrUAcLQfWygl90Z04D9Q][inet[/192.168.4.161:9301]],}, reason: zen-disc  
o-node\_failed([Aguja][RHkrUAcLQfWygl90Z04D9Q][inet[/192.168.4.161:9301]]), reaso  
n transport disconnected (with verified connect)

And finally i have a index information...  
End get ...{"user":"kimchy","postDate":"2011-11-06T14:12:13.416Z","message":"trying out Elastic Search"}

Only if i create client node like an api:

```
Node node = nodeBuilder().client(true).node();
Client client = node.client();

GetResponse response = client.prepareGet("twitter", "tweet", "1")
	.execute()
	.actionGet();
			
System.out.println("End get ..."+response.sourceAsString());

```

all works fine, without errors...

Another thing, spring implementation create node with name (Aguja on log.txt) but on elasticsearch.properties was declared like (MyNode)...

I don't understand what i'm doing wrong.  
Do you known why i have this exceptions? And what i must do to avoid it?  
I added logs and ElasticSearchNodeFactoryBean class.

\<nabble\_a href="ElasticSearchNodeFactoryBean.java"\>ElasticSearchNodeFactoryBean.java\</nabble\_a\>

\<nabble\_a href="logs.txt"\>logs.txt\</nabble\_a\>

Please help me. Advance thank you very much.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 9, 2011, 8:52am UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/2 "2011-11-09T08:52:22Z")

</div>

First, I suggest to experiment without the spring overhead (or switch  
to guice ;)).

Then, why not create the node in java with @Configure:

[http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java)

and provide that properly configured instance as singleton to the  
whole application context?

Peter.

On Nov 8, 1:38 pm, steam [grandebu...@gmail.com](mailto:grandebu...@gmail.com) wrote:

> Hello,  
> I make intent to reuse class ElasticsearchNodeFactoryBean from article  
> 'Elasticsearch with Spring'  
> ([http://techo-ecco.com/blog/elasticsearch-with-spring/](http://techo-ecco.com/blog/elasticsearch-with-spring/)).
> 
> I have a problem with client node creation on localhost.  
> Can you help me please.
> 
> I start elasticsearch.bat from elastic folder, to create server node to  
> store in it the indexes.  
> Then i start a client node from my java main class with spring configuration  
> and want recover indexes from server node.  
> I was changed a little ElasticSearchNodeFactoryBean because node was not  
> recognized with master server node  
> (that created with elasticsearch.bat and named like MasterNode).  
> Both nodes works on localhost and with same jdk1.6 and elasticsearch-0.18.2
> 
> My snippets code and logs with my comments:
> 
> Spring applicationContext.xml
> 
> ```
> <bean id="searchNode"
> 
> ```
> 
> class="com.web.project.elasticsearch.ElasticSearchNodeFactoryBean"\>
> 
> ```
> <bean id="searchClient" factory-bean="searchNode" factory-method="client"
> 
> ```
> 
> /\>
> 
> elasticsearch.properties
> 
> ```
> node.name=MyNode
> node.client=true
> node.local=true
> node.data=false
> index.number_of_shards=3
> index.store.fs.memory.enabled=false
> index.analysis.analyzer.projectx_standard.type=standard
> index.analysis.analyzer.projectx_standard.filter=[lowercase]
> 
> ```
> 
> And code to get index:
> 
> ```
> ClassPathXmlApplicationContext ctx =
> new
> 
> ```
> 
> ClassPathXmlApplicationContext("classpath:/spring/applicationContext.xml");
> 
> ```
> Client client = (Client) ctx.getBean("searchClient");
> 
> GetResponse response = client.prepareGet("twitter", "tweet", "1")
> .execute()
> .actionGet();
> 
> System.out.println("End get ..."+response.sourceAsString());
> 
> ```
> 
> When I run test on server node (MasterNode) i have a lot of exeptions:
> 
> java.io.IOException: Se ha forzado la interrupci¾n de una conexi¾n existente  
> por  
> el host remoto  
> at sun.nio.ch.SocketDispatcher.read0(Native Method)  
> at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)  
> at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)  
> at sun.nio.ch.IOUtil.read(IOUtil.java:200)  
> at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioW  
> orker.java:321)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSe  
> lectedKeys(NioWorker.java:280)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWo  
> rker.java:200)  
> at  
> org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(Thread  
> RenamingRunnable.java:108)  
> at  
> [org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru](http://org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru)  
> n(DeadLockProofWorker.java:44)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec  
> utor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor  
> .java:908)  
> at java.lang.Thread.run(Thread.java:619)  
> [2011-11-08 13:01:45,311][WARN][transport.netty] [MasterNode]  
> Excepti  
> on caught on netty layer [[id: 0x01c8f59c, /192.168.4.161:4421 =\>  
> /192.168.4.161  
> :9300]]  
> java.io.IOException: Se ha forzado la interrupci¾n de una conexi¾n existente  
> por  
> el host remoto  
> at sun.nio.ch.SocketDispatcher.read0(Native Method)  
> at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)  
> at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)  
> at sun.nio.ch.IOUtil.read(IOUtil.java:200)  
> at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioW  
> orker.java:321)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.processSe  
> lectedKeys(NioWorker.java:280)  
> at  
> org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWo  
> rker.java:200)  
> at  
> org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(Thread  
> RenamingRunnable.java:108)  
> at  
> [org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru](http://org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.ru)  
> n(DeadLockProofWorker.java:44)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec  
> utor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor  
> .java:908)  
> at java.lang.Thread.run(Thread.java:619)  
> [2011-11-08 13:01:46,108][INFO][cluster.service] [MasterNode]  
> removed  
> {[Aguja][RHkrUAcLQfWygl90Z04D9Q][inet[/192.168.4.161:9301]],}, reason:  
> zen-disc  
> o-node\_failed([Aguja][RHkrUAcLQfWygl90Z04D9Q][inet[/192.168.4.161:9301]]),  
> reaso  
> n transport disconnected (with verified connect)
> 
> And finally i have a index information...  
> End get  
> ...{"user":"kimchy","postDate":"2011-11-06T14:12:13.416Z","message":"trying  
> out Elastic Search"}
> 
> Only if i create client node like an api:
> 
> ```
> Node node = nodeBuilder().client(true).node();
> Client client = node.client();
> 
> GetResponse response = client.prepareGet("twitter", "tweet", "1")
> .execute()
> .actionGet();
> 
> System.out.println("End get ..."+response.sourceAsString());
> 
> ```
> 
> all works fine, without errors...
> 
> Another thing, spring implementation create node with name (Aguja on  
> log.txt) but on elasticsearch.properties was declared like (MyNode)...
> 
> I don't understand what i'm doing wrong.  
> Do you known why i have this exceptions? And what i must do to avoid it?  
> I added logs and ElasticSearchNodeFactoryBean class.
> 
> [http://elasticsearch-users.115913.n3.nabble.com/file/n3490143/Elastic](http://elasticsearch-users.115913.n3.nabble.com/file/n3490143/Elastic)...  
> ElasticSearchNodeFactoryBean.java
> 
> [http://elasticsearch-users.115913.n3.nabble.com/file/n3490143/logs.txt](http://elasticsearch-users.115913.n3.nabble.com/file/n3490143/logs.txt)  
> logs.txt
> 
> Please help me. Advance thank you very much.
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client](http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![steam](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@steam](https://discuss.elastic.co/u/steam)\
**Post date:** [November 9, 2011, 9:51am UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/3 "2011-11-09T09:51:42Z")

</div>

Thanks to replying.  
You suggest to create Node bean with @Configuration ?  
Sorry but i don't understand exactly what you mean, can you explain more detailed please.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 9, 2011, 8:05pm UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/4 "2011-11-09T20:05:42Z")

</div>

Springs' @Configuration is not really elasticsearch related but you  
can create the transport client as a bean:

@Configuration public class AppConfig {  
@Bean public Client myClient() {  
Node node = nodeBuilder().client(true).node();  
return node.client();  
}  
}

so this should be the same as you did where it works without error ...

Peter.

On Nov 9, 10:51 am, steam [grandebu...@gmail.com](mailto:grandebu...@gmail.com) wrote:

> Thanks to replying.  
> You suggest to create Node bean with @Configuration ?  
> Sorry but i don't understand exactly what you mean, can you explain more  
> detailed please.
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client](http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 9, 2011, 8:06pm UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/5 "2011-11-09T20:06:56Z")

</div>

ups, it is better to use the transport client where you don't need to  
have the node within the app server:

Settings s = ImmutableSettings.settingsBuilder().put("cluster.name",  
cluster).build();  
TransportClient client = new TransportClient(s);  
client.addTransportAddress(new InetSocketTransportAddress(url, port));  
return client;

Peter.

On Nov 9, 9:05 pm, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> Springs' @Configuration is not really elasticsearch related but you  
> can create the transport client as a bean:
> 
> @Configuration public class AppConfig {  
> @Bean public Client myClient() {  
> Node node = nodeBuilder().client(true).node();  
> return node.client();  
> }
> 
> }
> 
> so this should be the same as you did where it works without error ...
> 
> Peter.
> 
> On Nov 9, 10:51 am, steam [grandebu...@gmail.com](mailto:grandebu...@gmail.com) wrote:
> 
> > Thanks to replying.  
> > You suggest to create Node bean with @Configuration ?  
> > Sorry but i don't understand exactly what you mean, can you explain more  
> > detailed please.
> 
> > --  
> > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client](http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client)...  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![steam](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@steam](https://discuss.elastic.co/u/steam)\
**Post date:** [November 10, 2011, 10:01am UTC](https://discuss.elastic.co/t/need-help-with-client-node-creation-spring-on-localhost/5810/6 "2011-11-10T10:01:25Z")

</div>

Peter thanks a lot for your help and ideas 🙂  
I implemented and it seems work without errors.  
Regards 😉

2011/11/9 Karussell [via Elasticsearch Users] \<  
[ml-node+s115913n3494683h67@n3.nabble.com](mailto:ml-node+s115913n3494683h67@n3.nabble.com)\>

> ups, it is better to use the transport client where you don't need to  
> have the node within the app server:
> 
> Settings s = ImmutableSettings.settingsBuilder().put("cluster.name",  
> cluster).build();  
> TransportClient client = new TransportClient(s);  
> client.addTransportAddress(new InetSocketTransportAddress(url, port));  
> return client;
> 
> Peter.
> 
> On Nov 9, 9:05 pm, Karussell \<[hidden email][http://user/SendEmail.jtp?type=node&node=3494683&i=0](http://user/SendEmail.jtp?type=node&node=3494683&i=0)\>  
> wrote:
> 
> > Springs' @Configuration is not really elasticsearch related but you  
> > can create the transport client as a bean:
> > 
> > @Configuration public class AppConfig {  
> > @Bean public Client myClient() {  
> > Node node = nodeBuilder().client(true).node();  
> > return node.client();  
> > }
> > 
> > }
> > 
> > so this should be the same as you did where it works without error ...
> > 
> > Peter.
> > 
> > On Nov 9, 10:51 am, steam \<[hidden email][http://user/SendEmail.jtp?type=node&node=3494683&i=1](http://user/SendEmail.jtp?type=node&node=3494683&i=1)\>  
> > wrote:
> > 
> > > Thanks to replying.  
> > > You suggest to create Node bean with @Configuration ?  
> > > Sorry but i don't understand exactly what you mean, can you explain  
> > > more  
> > > detailed please.
> > 
> > > --  
> > > View this message in context:  
> > > [http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client](http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client)...  
> > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> * * *
> 
> If you reply to this email, your message will be added to the discussion  
> below:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client-node-creation-spring-on-localhost-tp3490143p3494683.html](http://elasticsearch-users.115913.n3.nabble.com/need-help-with-client-node-creation-spring-on-localhost-tp3490143p3494683.html)  
> To unsubscribe from need help with client node creation spring on  
> localhost :(, click here[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe\_by\_code&node=3490143&code=Z3JhbmRlYnV6b25AZ21haWwuY29tfDM0OTAxNDN8NzczOTUyOTkw](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3490143&code=Z3JhbmRlYnV6b25AZ21haWwuY29tfDM0OTAxNDN8NzczOTUyOTkw)  
> .  
> See how NAML generates this email[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro\_viewer&id=instant\_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails!nabble%3Aemail.naml-instant\_emails!nabble%3Aemail.naml-send\_instant\_email!nabble%3Aemail.naml](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml)

---

<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/need-help-with-client-node-creation-spring-on-localhost/5810/7 "2017-07-06T03:49:11Z")

</div>


