Why can't I connect to ElasticSearch through Java API? -
i'm having trouble connecting vanilla elasticsearch cluster via java api.
to reproduce:
#start elasticsearch elasticsearch -f #checking in new window $ curl -xput 'http://localhost:9200/twitter/tweet/1' -d '{\ "user" : "kimchy",\ "post_date" : "2009-11-15t14:12:12",\ "message" : "trying out elastic search"\ }'
result:
{ "ok": true, "_index": "twitter", "_type": "tweet", "_id": "1", "_version": 3 }
$ curl -xget 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'
result:
{ "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.30685282, "hits": [ { "_index": "twitter", "_type": "tweet", "_id": "1", "_score": 0.30685282, "_source": { "user": "kimchy", "post_date": "2009-11-15t14:12:12", "message": "trying out elastic search" } } ] } }
so, works via http. trying via java (per this page):
public static void main(string[] args) { client client = new transportclient() .addtransportaddress(new inetsockettransportaddress("localhost", 9200)); indexresponse response = null; try { response = client.prepareindex("twitter", "tweet", "1") .setsource(xcontentfactory.jsonbuilder() .startobject() .field("user", "john") .field("postdate", new date()) .field("message", "who dont work") .endobject() ) .execute() .actionget(); } catch (elasticsearchexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } system.out.println(response); }
and following stack trace:
may 21, 2013 8:27:42 org.elasticsearch.plugins info: [bes] loaded [], sites [] may 21, 2013 8:27:49 org.elasticsearch.client.transport info: [bes] failed node info [#transport#-1][inet[localhost/127.0.0.1:9200]], disconnecting... org.elasticsearch.transport.receivetimeouttransportexception: [][inet[localhost/127.0.0.1:9200]][cluster/nodes/info] request_id [0] timed out after [5002ms] @ org.elasticsearch.transport.transportservice$timeouthandler.run(transportservice.java:342) @ java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:895) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:918) @ java.lang.thread.run(thread.java:680) exception in thread "main" org.elasticsearch.client.transport.nonodeavailableexception: no node available @ org.elasticsearch.client.transport.transportclientnodesservice.execute(transportclientnodesservice.java:202) @ org.elasticsearch.client.transport.support.internaltransportclient.execute(internaltransportclient.java:106) @ org.elasticsearch.client.support.abstractclient.index(abstractclient.java:84) @ org.elasticsearch.client.transport.transportclient.index(transportclient.java:310) @ org.elasticsearch.action.index.indexrequestbuilder.doexecute(indexrequestbuilder.java:315) @ org.elasticsearch.action.actionrequestbuilder.execute(actionrequestbuilder.java:62) @ org.elasticsearch.action.actionrequestbuilder.execute(actionrequestbuilder.java:57) @ scratch.main(scratch.java:30)
and closest thing i've found far problem here, thread trailed off without resolution.
the transportclient default port 9300. have use instead of 9200 in java code. why connection fails.
Comments
Post a Comment