0

I am trying to use elastic search for searching I am successful to search keyword using URI search using rest client but I am unable to search using request body search below is the code for requestbody search please suggest what i am doing wrong there.

 RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
 HttpEntity entity = new NStringEntity("{\n" +
            "    \"query\" : {\n" +
            "        \"term\" : { \"chaData\" : \"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();
charmi
  • 197
  • 3
  • 17
  • have you check this response before https://stackoverflow.com/a/34928414/721600 – hkulekci Jun 07 '17 at 06:00
  • I am using restClient and if it is not attaching entity still "/cha/elasticSearch/_search?pretty" will return all entries in type elasticsearch but it shows total=0. – charmi Jun 07 '17 at 06:15

1 Answers1

0

Have you tried without the ?pretty - part. It looks like the restclient.performRequest() would like the query string as a map instead of as part of the endpoint? (you are passing an empty map instead)

jonasfh
  • 4,151
  • 2
  • 21
  • 37
  • {"took":52,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}} No success after removing pretty also still it gives 0 total. – charmi Jun 08 '17 at 05:00