Java equivalent of GET cURL command?

What is the java equivalent code for the following cURL command?

curl -XGET "http://localhost:9200/index1/type1/_search" -H 'Content-Type: application/json' -d'
  "query": {
    "match": {
      "Tag": "Value1"

I know how to do a Apache httpPost in java but how do I do httpGet with data?
I tried the following:

	String jsonGet = "{"+
				 "\"query\": {" +
				    "\"match\": {"+
				      "\"Tag\": \"Value1\""+
		    HttpGet httpGet = new HttpGet("http://localhost:9200/index1/type1/_search?" + URLEncoder.encode(jsonGet,"UTF-8"));

Use Post instead. May be your client does not allow Get with a body?

I wasn't (and still not) sure how to do POST to _search.
The following worked for me:

Response response = restClient.performRequest("GET", "index1/type1/_search",Collections.singletonMap("pretty", "true"), entity1);

where entity1 is an HttpEntity which contains the above jsonGet data.
I hope this helps someone in future.

1 Like

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