Hi I am writing custom plugin for elastic search, but I unable to get the parameter from the post request.
@Inject
public HelloRestHandler(Settings settings, RestController restController, Client esClient) {
super(settings, restController, esClient);
restController.registerHandler(RestRequest.Method.GET, "/_hello", this);
restController.registerHandler(RestRequest.Method.POST, "/_hello", this);
restController.registerHandler(RestRequest.Method.PUT, "/_hello", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, Client esClient) {
ObjectMapper mapper = new ObjectMapper();
String json;
try{json= mapper.writeValueAsString(request.params());}catch (Exception exp){ json ="not found";}
channel.sendResponse(new BytesRestResponse(OK,json));}
The curl:
curl -XPOST "http://localhost:9200/_hello/" -d '{"first":"1"}'
response :
"{}" (empty JSON)
Please help me out to fix my issue. Thanks.