# Java equivalent of GET cURL command?

**URL:** <https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348>\
**Category:** Elasticsearch\
**Created:** [June 29, 2017, 10:30pm UTC](https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348 "2017-06-29T22:30:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [June 29, 2017, 10:30pm UTC](https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348/1 "2017-06-29T22:30:51Z")

</div>

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"));
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 30, 2017, 3:57am UTC](https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348/2 "2017-06-30T03:57:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [June 30, 2017, 10:32pm UTC](https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348/3 "2017-06-30T22:32:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 28, 2017, 10:33pm UTC](https://discuss.elastic.co/t/java-equivalent-of-get-curl-command/91348/4 "2017-07-28T22:33:45Z")

</div>

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