Hi Ivan,
Below given is my custom class. How do I direct my search queries to this
end-point using the ES-Java API.
public class CustomRestAction extends BaseRestHandler {
@Inject
public CustomRestAction(Settings settings, Client client, RestController
controller) {
super(settings, client);
controller.registerHandler(Method.GET, "/_mastering/nodes", this);
}
@Override
public void handleRequest(RestRequest request, RestChannel channel) {
String prefix = request.param("prefix", "");
NodesInfoResponse response =
client.admin().cluster().prepareNodesInfo().all().execute().actionGet();
List nodes = new ArrayList();
for (NodeInfo nodeInfo : response.getNodes()) {
String nodeName = nodeInfo.getNode().getName();
if (prefix.isEmpty()) {
nodes.add(nodeName);
} else if (nodeName.startsWith(prefix)) {
nodes.add(nodeName);
}
}
try {
sendResponse(request, channel, nodes);
} catch (IOException ioe) {
logger.error("Error sending response", ioe);
}
return;
}
private void sendResponse(RestRequest request, RestChannel channel, List
nodes) throws IOException {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject().startArray("nodes");
if (!nodes.isEmpty()) {
builder.value(nodes);
}
builder.endArray().endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK,
builder));
}
}
public class CustomRestActionPlugin extends AbstractPlugin {
@Inject
public CustomRestActionPlugin(Settings settings) {
}
public void onModule(RestModule module) {
module.addRestAction(CustomRestAction.class);
}
@Override
public String name() {
return "CustomRestActionPlugin";
}
@Override
public String description() {
return "Custom REST action";
}
}
On Thursday, 2 January 2014 23:52:51 UTC+5:30, Ivan Brusic wrote:
You would need to supply information about your custom class for more
details. Did you create a new Action hierarchy? The handleRequest method of
your BaseRestHandler implementation should provide details on how the Java
API is used.
Cheers,
Ivan
On Thu, Jan 2, 2014 at 5:14 AM, Shishir Kumar <shishi...@gmail.com<javascript:>
wrote:
Hi,
I have implemented a simple custom rest handler class for Elasticsearch.
If I need to call it using curl it works just fine.
curl -XGET '10.114.24.132:9200/_mastering/nodes?pretty'
However, I want to call this using the Elasticsearch Java api (with an
embedded client node). Could you please help me with this? I am new to
Elasticsearch and not able to figure this out.
P.S. I had followed the instructions given in the link <
http://elasticsearchserverbook.com/creating-custom-elasticsearch-rest-action/>
for setting up the custom handler.
--
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/6a352a4d-3ac6-4970-95de-80d56e4d7dec%40googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.
--
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/fb4f8bf3-c32d-4f77-964b-ec31ab8c5060%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.