Not able to do request body search using rest client elasticsearch 5.4

Hello All,
I just started with elastic search. I am using latest 5.4 version and rest client of it in Spring. Although I am successful to do uri search but I want to use request body search and below is my Code but it is givind total:0 and also given equivalent uri search which give me total:4 result. Please help me.


Request body Search code :=

RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
HttpEntity entity = new NStringEntity("{\n" +
        "    \"query\" : {\n" +
        "        \"term\" : { \"pdfData\" : \"ADMINISTRATOR\" }\n" +
        "    }\n" +
        "}", ContentType.APPLICATION_JSON);
Response indexResponse = restClient.performRequest("POST",
        "/cha/elasticSearch/_search?pretty",Collections.<String, String>emptyMap(),entity);
System.out.println(EntityUtils.toString(indexResponse.getEntity()));
restClient.close();

uri search code :=

        RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
        Response indexResponse = restClient.performRequest("GET","/agd/elasticSearch/_search?pretty&q=pdfData:ADMINISTRATOR",Collections.<String, String>emptyMap());
        System.out.println(EntityUtils.toString(indexResponse.getEntity());       
        restClient.close();

Hi,
did you try running the same with curl or from the Kibana Console? I suspect that the problem is not in the way you use the REST client, but more in the query. Your search request with a request body looks good to me at first glance.

Cheers
Luca

Thanks for reply. Yes today only I tried another query and it worked.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.