Need help with client node creation spring on localhost :(

Hello,
I make intent to reuse class ElasticsearchNodeFactoryBean from article '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
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
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.

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

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

Peter.

On Nov 8, 1:38 pm, steam 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/).

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
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
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...
ElasticSearchNodeFactoryBean.java

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...
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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.

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 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...
Sent from the Elasticsearch Users mailing list archive at 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 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 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...
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Peter thanks a lot for your help and ideas :slight_smile:
I implemented and it seems work without errors.
Regards :wink:

2011/11/9 Karussell [via Elasticsearch Users] <
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>
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>
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...
Sent from the Elasticsearch Users mailing list archive at 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
To unsubscribe from need help with client node creation spring on
localhost :(, click herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3490143&code=Z3JhbmRlYnV6b25AZ21haWwuY29tfDM0OTAxNDN8NzczOTUyOTkw
.
See how NAML generates this emailhttp://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