Getting started with ElasticSearch with JAVA API

Hi,
I am new to elastic search and having problem in connecting the node with
Java API.
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
Client client = new
TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress("localhost", 9200));
I am trying to get the node and create the index on it with this code. And
I am getting Exception on nettyLayer..
Where when it using httpput , I am able to get the index created.
HttpPut httpPut = new HttpPut("http://localhost:9200/data/big/1");
httpPut.addHeader("Accept", "application/json");
httpPut.addHeader("Content-Type",
"application/json");
JSONObject json = new JSONObject();
json.put("name", "testing");
json.put("message", "adding new index");
StringEntity entity = new
StringEntity(json.toString(), "UTF-8");
entity.setContentType("application/json");

                        httpPut.setEntity(entity);
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse response = httpClient 

.execute(httpPut);
Please help me out in this regard.

--

Why don't you use the real Java API instead of the REST API?

Take a look at:
http://www.elasticsearch.org/guide/reference/java-api/

Best regards,

Robin Verlangen
Software engineer
*
*
W http://www.robinverlangen.nl
E robin@us2.nl

Disclaimer: The information contained in this message and attachments is
intended solely for the attention and use of the named addressee and may be
confidential. If you are not the intended recipient, you are reminded that
the information remains the property of the sender. You must not use,
disclose, distribute, copy, print or rely on this e-mail. If you have
received this message in error, please contact the sender immediately and
irrevocably delete this message and any copies.

2012/9/18 ali ilyas mmaipucit@gmail.com

Hi,
I am new to elastic search and having problem in connecting the node with
Java API.
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
Client client = new
TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress("localhost", 9200));
I am trying to get the node and create the index on it with this code.
And I am getting Exception on nettyLayer..
Where when it using httpput , I am able to get the index created.
HttpPut httpPut = new HttpPut("http://localhost:9200/data/big/1");
httpPut.addHeader("Accept",
"application/json");
httpPut.addHeader("Content-Type",
"application/json");
JSONObject json = new JSONObject();
json.put("name", "testing");
json.put("message", "adding new index");
StringEntity entity = new
StringEntity(json.toString(), "UTF-8");
entity.setContentType("application/json");

                        httpPut.setEntity(entity);
                        HttpClient httpClient = new

DefaultHttpClient();
HttpResponse response = httpClient
.execute(httpPut);
Please help me out in this regard.

--

--

I am using JAVA API and getting the exception , where if I use rest
framework, it works fine.

On Tuesday, September 18, 2012 6:47:30 PM UTC+2, Robin Verlangen wrote:

Why don't you use the real Java API instead of the REST API?

Take a look at:
http://www.elasticsearch.org/guide/reference/java-api/

Best regards,

Robin Verlangen
Software engineer
*
*
W http://www.robinverlangen.nl
E ro...@us2.nl <javascript:>

Disclaimer: The information contained in this message and attachments is
intended solely for the attention and use of the named addressee and may be
confidential. If you are not the intended recipient, you are reminded that
the information remains the property of the sender. You must not use,
disclose, distribute, copy, print or rely on this e-mail. If you have
received this message in error, please contact the sender immediately and
irrevocably delete this message and any copies.

2012/9/18 ali ilyas <mmai...@gmail.com <javascript:>>

Hi,
I am new to elastic search and having problem in connecting the node with
Java API.
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
Client client = new
TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress("localhost", 9200));
I am trying to get the node and create the index on it with this code.
And I am getting Exception on nettyLayer..
Where when it using httpput , I am able to get the index created.
HttpPut httpPut = new HttpPut("http://localhost:9200/data/big/1");
httpPut.addHeader("Accept",
"application/json");
httpPut.addHeader("Content-Type",
"application/json");
JSONObject json = new JSONObject();
json.put("name", "testing");
json.put("message", "adding new index");
StringEntity entity = new
StringEntity(json.toString(), "UTF-8");
entity.setContentType("application/json");

                        httpPut.setEntity(entity);
                        HttpClient httpClient = new 

DefaultHttpClient();
HttpResponse response = httpClient
.execute(httpPut);
Please help me out in this regard.

--

--

Hi Ali,

What Robin means to say is that you should be using the ElasticSearch
Java API, and not use other REST/web libraries, even if they are in
Java.

There is no need for HttpPut, HttpClient, etc... Simple use the
methods defined in org.elasticsearch.client.Client. The guide could do
a better job at providing a front to back usage of the client object,
but the basics are there. Take a look at creating an index using the
Java API:

http://www.elasticsearch.org/guide/reference/java-api/index_.html

The mailing list has tons of examples, and while it might be hard to
search for code, you should still find something. Hopefully this can
be a start.

Cheers,

Ivan

On Tue, Sep 18, 2012 at 9:57 AM, ali ilyas mmaipucit@gmail.com wrote:

I am using JAVA API and getting the exception , where if I use rest
framework, it works fine.

On Tuesday, September 18, 2012 6:47:30 PM UTC+2, Robin Verlangen wrote:

Why don't you use the real Java API instead of the REST API?

Take a look at:
http://www.elasticsearch.org/guide/reference/java-api/

Best regards,

Robin Verlangen
Software engineer

W http://www.robinverlangen.nl
E ro...@us2.nl

Disclaimer: The information contained in this message and attachments is
intended solely for the attention and use of the named addressee and may be
confidential. If you are not the intended recipient, you are reminded that
the information remains the property of the sender. You must not use,
disclose, distribute, copy, print or rely on this e-mail. If you have
received this message in error, please contact the sender immediately and
irrevocably delete this message and any copies.

2012/9/18 ali ilyas mmai...@gmail.com

Hi,
I am new to elastic search and having problem in connecting the node with
Java API.
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
Client client = new
TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress("localhost", 9200));
I am trying to get the node and create the index on it with this code.
And I am getting Exception on nettyLayer..
Where when it using httpput , I am able to get the index created.
HttpPut httpPut = new HttpPut("http://localhost:9200/data/big/1");
httpPut.addHeader("Accept",
"application/json");
httpPut.addHeader("Content-Type",
"application/json");
JSONObject json = new JSONObject();
json.put("name", "testing");
json.put("message", "adding new index");
StringEntity entity = new
StringEntity(json.toString(), "UTF-8");
entity.setContentType("application/json");

                        httpPut.setEntity(entity);
                        HttpClient httpClient = new

DefaultHttpClient();
HttpResponse response = httpClient
.execute(httpPut);
Please help me out in this regard.

--

--

--

The Java TransportClient Service is using port 9300, not 9200.

For a quick example, see one of kimchy's
gists https://gist.github.com/2513321

Hope this helps,

Jörg

On Tuesday, September 18, 2012 6:43:01 PM UTC+2, ali ilyas wrote:

Hi,
I am new to elastic search and having problem in connecting the node with
Java API.
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch").build();
Client client = new
TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress("localhost", 9200));
I am trying to get the node and create the index on it with this code.
And I am getting Exception on nettyLayer..
Where when it using httpput , I am able to get the index created.
HttpPut httpPut = new HttpPut("http://localhost:9200/data/big/1");
httpPut.addHeader("Accept",
"application/json");
httpPut.addHeader("Content-Type",
"application/json");
JSONObject json = new JSONObject();
json.put("name", "testing");
json.put("message", "adding new index");
StringEntity entity = new
StringEntity(json.toString(), "UTF-8");
entity.setContentType("application/json");

                        httpPut.setEntity(entity);
                        HttpClient httpClient = new 

DefaultHttpClient();
HttpResponse response = httpClient
.execute(httpPut);
Please help me out in this regard.

--

use JEST if you really want to some of the functionality of Apache HttpClient. In a project, i had a need to send custom headers, JEST had that capability plus the query building of the regular ES client API.