Migrating from the Java API to the REST API

Is there a simple way to reuse code that was written using
elasticsearch's Java API to use the REST API instead, or do I need to
start from scratch?

Hi,

you probably need to be more specific. For example:

  • are you going to use it directly or via some existing client? (Perl,
    Ruby, ... etc)
  • what are you doing with the Java API? Are you doing more then just
    querying and indexing? For example, do you perform any admin API calls?

Without knowing more details I would say that you probably need to rewrite
your queries into query DSL and you may need to check cluster nodes stats
yourself regularly to learn how many nodes are active and which of them are
HTTP enabled and load balance between them (probably some REST clients can
do this for you). You may also need to think about deploying some proxy
server for security reasons.

Regards,
Lukas

On Mon, Apr 16, 2012 at 10:18 PM, Eric Jain eric.jain@gmail.com wrote:

Is there a simple way to reuse code that was written using
elasticsearch's Java API to use the REST API instead, or do I need to
start from scratch?

On Mon, Apr 16, 2012 at 14:23, Lukáš Vlček lukas.vlcek@gmail.com wrote:

you probably need to be more specific. For example:

  • are you going to use it directly or via some existing client? (Perl, Ruby,
    ... etc)

I'm using (and will continue to use) elasticsearch from a Java application only.

  • what are you doing with the Java API? Are you doing more then just
    querying and indexing? For example, do you perform any admin API calls?

I use quite a bit of the API, including client.prepareXYZ and
client.admin().indices().prepareXYZ.

I was hoping there would be a simple way to convert e.g. a
PutMappingRequest object to json that can be sent to the REST API. But
it looks like I'll need to write my own json request builder code?

Without knowing more details I would say that you probably need to rewrite
your queries into query DSL and you may need to check cluster nodes stats
yourself regularly to learn how many nodes are active and which of them are
HTTP enabled and load balance between them (probably some REST clients can
You may also need to think about deploying some proxy
server for security reasons.

Yes, I'll have a password-protected load balancer.

On Mon, Apr 16, 2012 at 11:43 PM, Eric Jain eric.jain@gmail.com wrote:

On Mon, Apr 16, 2012 at 14:23, Lukáš Vlček lukas.vlcek@gmail.com wrote:

you probably need to be more specific. For example:

  • are you going to use it directly or via some existing client? (Perl,
    Ruby,
    ... etc)

I'm using (and will continue to use) elasticsearch from a Java application
only.

  • what are you doing with the Java API? Are you doing more then just
    querying and indexing? For example, do you perform any admin API calls?

I use quite a bit of the API, including client.prepareXYZ and
client.admin().indices().prepareXYZ.

I was hoping there would be a simple way to convert e.g. a
PutMappingRequest object to json that can be sent to the REST API. But
it looks like I'll need to write my own json request builder code?

I am not sure if that is possible for every Java API request but it is
possible at least for some of them. For example, if you can
get org.elasticsearch.search.builder.SearchSourceBuilder then you can call
toString() on it which will give you JSON string that you are looking for.

HTH

Without knowing more details I would say that you probably need to
rewrite
your queries into query DSL and you may need to check cluster nodes stats
yourself regularly to learn how many nodes are active and which of them
are
HTTP enabled and load balance between them (probably some REST clients
can
You may also need to think about deploying some proxy
server for security reasons.

Yes, I'll have a password-protected load balancer.

On Mon, Apr 16, 2012 at 16:19, Lukáš Vlček lukas.vlcek@gmail.com wrote:

I am not sure if that is possible for every Java API request but it is
possible at least for some of them. For example, if you can
get org.elasticsearch.search.builder.SearchSourceBuilder then you can call
toString() on it which will give you JSON string that you are looking for.

Too bad this doesn't work for SearchRequest.toString() as well...

Using the client libs will be meaningless in this case, you will need to
write something that generates the correct HTTP request and response.

On Tue, Apr 17, 2012 at 3:15 AM, Eric Jain eric.jain@gmail.com wrote:

On Mon, Apr 16, 2012 at 16:19, Lukáš Vlček lukas.vlcek@gmail.com wrote:

I am not sure if that is possible for every Java API request but it is
possible at least for some of them. For example, if you can
get org.elasticsearch.search.builder.SearchSourceBuilder then you can
call
toString() on it which will give you JSON string that you are looking
for.

Too bad this doesn't work for SearchRequest.toString() as well...