# Best Practice: does anybody use GET with BODY?

**URL:** <https://discuss.elastic.co/t/best-practice-does-anybody-use-get-with-body/6990>\
**Category:** Elasticsearch\
**Created:** [March 14, 2012, 9:42am UTC](https://discuss.elastic.co/t/best-practice-does-anybody-use-get-with-body/6990 "2012-03-14T09:42:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian\_mayo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ian_mayo/32/2324_2.png) [@ian\_mayo](https://discuss.elastic.co/u/ian_mayo)\
**Post date:** [March 14, 2012, 9:42am UTC](https://discuss.elastic.co/t/best-practice-does-anybody-use-get-with-body/6990/1 "2012-03-14T09:42:17Z")

</div>

Hi all,  
I'm trying to collate my queries into a BODY JSON object, and then firing  
that object via a GET call.

But, the REST utilities I'm using don't like supporting a BODY for GET  
calls. In fact, Roy Fielding has recommended against it:  
[http://tech.groups.yahoo.com/group/rest-discuss/message/9962](http://tech.groups.yahoo.com/group/rest-discuss/message/9962)

The elasticsearch examples all use -d, with the JSON in a string. But, the  
man page for CURL states that -d "sends the specified data in a POST  
request":  
[http://unixhelp.ed.ac.uk/CGI/man-cgi?curl](http://unixhelp.ed.ac.uk/CGI/man-cgi?curl)

So, it appears the use of -d isn't compliant with the spec for CURL.

Am I missing something here?

Whilst exploring the ES REST-API, is there a tidy way of collating a query  
as JSON and then passing that into the GET?

cheers,  
Ian

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 14, 2012, 9:59am UTC](https://discuss.elastic.co/t/best-practice-does-anybody-use-get-with-body/6990/2 "2012-03-14T09:59:51Z")

</div>

Hiya

> I'm trying to collate my queries into a BODY JSON object, and then  
> firing that object via a GET call.

What do you mean by "collate my queries"? Multiple queries? or do you  
mean that you are building a single query?

> But, the REST utilities I'm using don't like supporting a BODY for GET  
> calls. In fact, Roy Fielding has recommended against it:  
> [http://tech.groups.yahoo.com/group/rest-discuss/message/9962](http://tech.groups.yahoo.com/group/rest-discuss/message/9962)

Personally, I disagree with the GET-can't-contain-a-body argument,  
because the query string has a limited length. Conceptually, a search  
is a GET, not a POST.

Javascript doesn't support it, but most other HTTP libraries do.

> The elasticsearch examples all use -d, with the JSON in a string.  
> But, the man page for CURL states that -d "sends the specified data  
> in a POST request":  
> [http://unixhelp.ed.ac.uk/CGI/man-cgi?curl](http://unixhelp.ed.ac.uk/CGI/man-cgi?curl)

> So, it appears the use of -d isn't compliant with the spec for CURL.

It defaults to a POST, but you can specify whichever method you want  
with -X

> Am I missing something here?

You have two options:

1. search will also accept a POST request
2. you can pass the request body as the query string parameter 'source'  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/index.html)

> Whilst exploring the ES REST-API, is there a tidy way of collating a  
> query as JSON and then passing that into the GET?

I don't know what this sentence means 🙂

clint

---

<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 6, 2017, 3:36am UTC](https://discuss.elastic.co/t/best-practice-does-anybody-use-get-with-body/6990/3 "2017-07-06T03:36:16Z")

</div>


