Hi Everybody,
I am trying to use elasticsearch from Java. (I am running elasticsearch server locally on my laptop using java 6 in Windows 7 64 bits and the client under eclipse Indigo)
First of all I have followed the tutorial “ElasticSearch in 5 minutes” and I created a few indexed data as per tutorial. (e.i. http://localhost:9200/blog/post/1 (in particular “Dilbert Brown” item - using postman http://localhost:9200/blog/user/dilbert' '{ "name" : "Dilbert Brown" }').
I have checked that the record and it does exist – using again postman util.
Everything works fine from dos command prompt – as described by the tutorial
My question is: how do I retrieve it from elasticsearch using Java. I have tried this code?
Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
SearchResponse response = client.prepareSearch("mongoindex").setSearchType(
SearchType.DFS_QUERY_THEN_FETCH).setQuery(QueryBuilders.termQuery("name", "Dilbert Brown"))
.setFrom(0).setSize(60).setExplain(true).execute().actionGet();
SearchHit[] docs = response.getHits().getHits();
From prepareSearch method I am getting:
org.elasticsearch.client.transport.NoNodeAvailableException: No node available
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:205)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:206)
at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:365)
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:743)
at org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:53)
at org.elasticsearch.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:47)
at com.tycoint.eams.servlet.InitContextListener.contextInitialized(InitContextListener.java:94)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
What Am I doing wrong?
Regards,
Janusz