Converting rest api to java api

Hi all,

I am trying to build a proxy that will take elasticsearch requests that come in rest api form and convert them to elasicsearch's java api equivalent and then send and get the requests through 9300. I have seen how to transform some sample specific ES rest api calls and get them to work in Java api but i need to come up with a bit of a more generalized formula.

I have read on this forum and other websites that for elasticserach, eventually all rest api calls get transformed in java api. If anyone knows any info or where i could get more info on how ES internally converts rest calls to java api, i would greatly appreciate it.

Also, I have been searching through elasticsearch source code and am currently trying to play around with the AbstractClient.execute method since it is noted that this is the "single execution point of all clients".

from org.elasticserach.cleint.support.AbstractClient :
/**
* This is the single execution point of all clients.
*/
@Override
public final <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener listener) {
headers.applyTo(request);
listener = threadedWrapper.wrap(listener);
doExecute(action, request, listener);
}

If there is any other portions of the source code i should be looking into, and if you have any tips, advice, etc.. please let me know.

Thanks,
Jim

What problem are you trying to solve here? The reason I ask is that Elasticsearch has a 'client' node (a node that is neither a data node or a master node) that is used to route and load balance requests to the rest of the cluster. Maybe this is what you are after?

More information on Client nodes here: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-node.html#client-node

The HTTP code of ES in package org.elasticsearch.rest already translates REST API to Java API. So I'm not sure why you double the work?

Spin up a node with node.master: false and node.data: false, and you have your proxy node.

Hi Colin,

I am experimenting with trying to send my current rest calls coming in at 9200 to 9300 via java api. i want to see if i can then turn off 9200 and have these rest calls along with all my other sources come through 9300 java api so then i can more easily secure it with an ip tables firewall.

So now I am trying to invoke the dispatchRequest in the RestController in order to call the JAVA API for handling all my GET,POST,SEARCH requests and so that I dont have to manually decipher the URL to make the appropriate call, I need to hence have a handler to the RestController object, whats the best way to create it ? I came across the foll :

RestController controller = new RestController(Settings.EMPTY, Collections.emptySet());

,is this the right way of doing it ? Also, will I need to call registerHandler method on it ?

Thanks,
Jim

Thanks for your help Jorg