0

I am trying to search a query in indian language among texts indexed in elasticsearch. When I fire a POST request thru postman, I get that record, but when I test it thru swagger, it's not working

Snapshot of postman

String url =  "http://localhost:9200/mono/_doc/_search?pretty";
        CloseableHttpClient httpClient = (HttpClients.createDefault());
        HttpPost httpPost = new HttpPost(url);
    httpPost.setHeader("content-type", "application/json");
System.out.println("Request : " + httpPost);

        httpPost.setEntity(entity);
        // Execute and get the response after ingesting PO (purchase order) into
        // Globality.
        HttpResponse response = httpClient.execute(httpPost);
        String response2 = EntityUtils.toString(response.getEntity());

        if (response2 != null) {
            System.out.println(response2);
        }

Debug output from code:

json2 is

 {"query":{"match":{"body":{"fuzziness":"2","query":"जन्मभूमि"}}}}

Request :

POST http://localhost:9200/mono/_doc/_search?pretty HTTP/1.1

Response:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

So as we see above, no result is returned. Is it because of HTTP version 1.0. Does it need to be 2.0?. if yes, how to specify it?. Is it something to do with indian language specific issue?. But not able to understand how its working thru postman but not thru java code.

One more thing, in postman it works with both GET and POST. In code, I wanted to first use GET, but didn't know how to send body with the GET request, so ended up using POST.

1
  • 2
    Working now. Added: StringEntity entity = new StringEntity(jsonString,"UTF-8"); Commented Aug 6, 2020 at 2:29

1 Answer 1

1

Working now. Added: StringEntity entity = new StringEntity(jsonString,"UTF-8");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.