Java Client - Error Handling


(Nir Dothan) #1

I'm not sure how to handle errors when using the java client. How do I
grammatically know if my connection was successful, or if indexing of a
document succeeded?
In Rest we have the http result code, but in java, I did not see a
documented way to catch checked exceptions or anything like that.
For connection assurance I use:
return 0< client.admin().cluster().prepareState().get().getState().
getVersion();
Is that correct? is it effective?
Can anyone please refer my to any documentation or relevant source code?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Jörg Prante) #2

Do you use TransportClient or NodeClient?

On NodeClient, you are tied to the cluster, as the node is being a part of
it, on TransportClient, you can count the connected nodes.

The discovery mechanism behind the scenes sends "ping" actions each few
seconds for you. If an action fails, you will see exceptions there. No need
to ask explicitly the cluster for a state or something (your code also just
asks for the local state copy which has nothing to do with testing
connections)

Jörg

On Thu, Jun 5, 2014 at 1:29 PM, Nir Dothan nir.dothan@gmail.com wrote:

I'm not sure how to handle errors when using the java client. How do I
grammatically know if my connection was successful, or if indexing of a
document succeeded?
In Rest we have the http result code, but in java, I did not see a
documented way to catch checked exceptions or anything like that.
For connection assurance I use:
return 0< client.admin().cluster().prepareState().get().getState().
getVersion();
Is that correct? is it effective?
Can anyone please refer my to any documentation or relevant source code?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKdsXoG3HfOkDYbLqrwhT%3DHBXB1ipZwKtg3mDQbyJ3%3D4ZP0YFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Nir Dothan) #3

Thanks. The code I'm developing will support both Node and Transport
clients. The selection will be configuration driven.
There must be a way to determine if a CRUD operation succeeded. For
example, see the following code taken from the Logstash Ruby client based
plugin. Is there any Java client equivalent?

def template_exists?(name)
@client.indices.get_template(:name => name)
return true
rescue Elasticsearch::Transport::Transport::Errors::NotFound
return false
end # def template_exists?

In addition, for transport client do you recommend checking
client.connectedNodes().size() > 0 ?

On Thursday, June 5, 2014 3:44:25 PM UTC+3, Jörg Prante wrote:

Do you use TransportClient or NodeClient?

On NodeClient, you are tied to the cluster, as the node is being a part of
it, on TransportClient, you can count the connected nodes.

The discovery mechanism behind the scenes sends "ping" actions each few
seconds for you. If an action fails, you will see exceptions there. No need
to ask explicitly the cluster for a state or something (your code also just
asks for the local state copy which has nothing to do with testing
connections)

Jörg

On Thu, Jun 5, 2014 at 1:29 PM, Nir Dothan <nir.d...@gmail.com
<javascript:>> wrote:

I'm not sure how to handle errors when using the java client. How do I
grammatically know if my connection was successful, or if indexing of a
document succeeded?
In Rest we have the http result code, but in java, I did not see a
documented way to catch checked exceptions or anything like that.
For connection assurance I use:
return 0< client.admin().cluster().prepareState().get().getState().
getVersion();
Is that correct? is it effective?
Can anyone please refer my to any documentation or relevant source code?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5f4a13ee-25e2-40f4-8163-b19a718fa225%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Jörg Prante) #4

Check the Elasticsearch test code. There, you can see how Java API works.

For example

GetIndexTemplatesResponse response =
client().admin().indices().prepareGetTemplates().get();

You can get an empty response if template does not exist, or the execution
throws an exception, when something went wrong.

After initialization of TransportClient, you could check connectedNodes(),
yes. While running, you will get an exception if no node is connected, and
you execute an action.

Jörg

On Thu, Jun 5, 2014 at 4:29 PM, Nir Dothan nir.dothan@gmail.com wrote:

Thanks. The code I'm developing will support both Node and Transport
clients. The selection will be configuration driven.
There must be a way to determine if a CRUD operation succeeded. For
example, see the following code taken from the Logstash Ruby client based
plugin. Is there any Java client equivalent?

def template_exists?(name)
@client.indices.get_template(:name => name)
return true
rescue Elasticsearch::Transport::Transport::Errors::NotFound
return false
end # def template_exists?

In addition, for transport client do you recommend checking
client.connectedNodes().size() > 0 ?

On Thursday, June 5, 2014 3:44:25 PM UTC+3, Jörg Prante wrote:

Do you use TransportClient or NodeClient?

On NodeClient, you are tied to the cluster, as the node is being a part
of it, on TransportClient, you can count the connected nodes.

The discovery mechanism behind the scenes sends "ping" actions each few
seconds for you. If an action fails, you will see exceptions there. No need
to ask explicitly the cluster for a state or something (your code also just
asks for the local state copy which has nothing to do with testing
connections)

Jörg

On Thu, Jun 5, 2014 at 1:29 PM, Nir Dothan nir.d...@gmail.com wrote:

I'm not sure how to handle errors when using the java client. How do I
grammatically know if my connection was successful, or if indexing of a
document succeeded?
In Rest we have the http result code, but in java, I did not see a
documented way to catch checked exceptions or anything like that.
For connection assurance I use:
return 0< client.admin().cluster().prepareState().get().getState().get
Version();
Is that correct? is it effective?
Can anyone please refer my to any documentation or relevant source code?

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearc...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/
msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%
40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/f98a54e0-efb0-47f8-a391-e2ec3920a3d1%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/5f4a13ee-25e2-40f4-8163-b19a718fa225%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/5f4a13ee-25e2-40f4-8163-b19a718fa225%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFgnUwZTb%3DGtL1iOcYnjYLMh80bD2NG4CaiW3GiVM868w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #5