# Is there any way to pass search query in POST parameter rather than body?

**URL:** <https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563>\
**Category:** Elasticsearch\
**Created:** [January 31, 2013, 2:43am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563 "2013-01-31T02:43:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [January 31, 2013, 2:43am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/1 "2013-01-31T02:43:43Z")

</div>

Hello,

For complete functionality, UI framework I use needs query be passed in  
POST parameters rather than body. Is there any way I can pass complete  
query I would normally pass in the body in POST parameter.

Using GET and URI is not an option - I need full query DSL

Thank you,  
Alex

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [January 31, 2013, 3:06am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/2 "2013-01-31T03:06:12Z")

</div>

I found a partial answer. one can pass complete query in GET source  
parameter. But the query I generate (with facet, facet filters + filtered  
(based on selected facet values) query can rather long. I would be more  
comfortable passing it as post parameter. I tried post with source  
parameter but unfortunately it does not work:

{"error":"SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], total failure; shardFailures{[pguRRu2dTzKk\_AMMcUO32w][award][0]: SearchParseException[[award][0]:  
from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested:  
ElasticSearchParseException[Failed to derive xcontent fromorg.elasticsearch.common.bytes.ChannelBufferBytesReference@61f0ab21];  
}]","status":500}

On Wednesday, January 30, 2013 9:43:43 PM UTC-5, AlexR wrote:

> Hello,
> 
> For complete functionality, UI framework I use needs query be passed in  
> POST parameters rather than body. Is there any way I can pass complete  
> query I would normally pass in the body in POST parameter.
> 
> Using GET and URI is not an option - I need full query DSL
> 
> Thank you,  
> Alex

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 31, 2013, 3:27am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/3 "2013-01-31T03:27:22Z")

</div>

Sorry. I don't understand. What do you mean by POST?  
This?

curl -XPOST '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '{  
"query": {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "some query string here"  
}  
},  
"filter" : {  
"term" : { "user" : "kimchy" }  
}  
}  
}  
}  
'

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 janv. 2013 à 04:06, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :

I found a partial answer. one can pass complete query in GET source parameter. But the query I generate (with facet, facet filters + filtered (based on selected facet values) query can rather long. I would be more comfortable passing it as post parameter. I tried post with source parameter but unfortunately it does not work:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query\_fetch], total failure; shardFailures {[pguRRu2dTzKk\_AMMcUO32w][award][0]: SearchParseException[[award][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@61f0ab21]; }]","status":500}

On Wednesday, January 30, 2013 9:43:43 PM UTC-5, AlexR wrote:

> Hello,
> 
> For complete functionality, UI framework I use needs query be passed in POST parameters rather than body. Is there any way I can pass complete query I would normally pass in the body in POST parameter.
> 
> Using GET and URI is not an option - I need full query DSL
> 
> Thank you,  
> Alex

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [January 31, 2013, 3:31am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/4 "2013-01-31T03:31:01Z")

</div>

I mean passing query in form-encoded parameters via POST as supposed to  
passing it in request body in raw  
just like with get you can pass parameters via query string, with post you  
can pass then form-encoded. web server (say servlet API) then would extract  
them and present it to you as parameters

On Wed, Jan 30, 2013 at 10:27 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Sorry. I don't understand. What do you mean by POST?  
> This?
> 
> curl -XPOST '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '{  
> "query": {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "some query string here"  
> }  
> },  
> "filter" : {  
> "term" : { "user" : "kimchy" }  
> }  
> }  
> }  
> }  
> '
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 janv. 2013 à 04:06, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :
> 
> I found a partial answer. one can pass complete query in GET source  
> parameter. But the query I generate (with facet, facet filters + filtered  
> (based on selected facet values) query can rather long. I would be more  
> comfortable passing it as post parameter. I tried post with source  
> parameter but unfortunately it does not work:
> 
> {"error":"SearchPhaseExecutionException[Failed to execute phase  
> [query\_fetch], total failure; shardFailures{[pguRRu2dTzKk\_AMMcUO32w][award][0]: SearchParseException[[award][0]:  
> from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]];  
> nested: ElasticSearchParseException[Failed to derive xcontent fromorg.elasticsearch.common.bytes.ChannelBufferBytesReference@61f0ab21];  
> }]","status":500}
> 
> On Wednesday, January 30, 2013 9:43:43 PM UTC-5, AlexR wrote:
> 
> > Hello,
> > 
> > For complete functionality, UI framework I use needs query be passed in  
> > POST parameters rather than body. Is there any way I can pass complete  
> > query I would normally pass in the body in POST parameter.
> > 
> > Using GET and URI is not an option - I need full query DSL
> > 
> > Thank you,  
> > Alex
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 31, 2013, 8:38am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/5 "2013-01-31T08:38:58Z")

</div>

I don't think you can. See Jörg answer: [https://groups.google.com/d/msg/elasticsearch/SzF0LhiVvqk/htn52x3xgmoJ](https://groups.google.com/d/msg/elasticsearch/SzF0LhiVvqk/htn52x3xgmoJ)

That said, you can do something like:

curl -XGET [http://localhost:9200/\_search?source=YOUR\_JSON\_HERE](http://localhost:9200/_search?source=YOUR_JSON_HERE)

curl 'localhost:9200/\_search?source={"query":{"term":{"user":"kimchy"}}}'

Does it help?

Le 31 janv. 2013 à 04:31, Alex Roytman [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :

> I mean passing query in form-encoded parameters via POST as supposed to passing it in request body in raw  
> just like with get you can pass parameters via query string, with post you can pass then form-encoded. web server (say servlet API) then would extract them and present it to you as parameters
> 
> On Wed, Jan 30, 2013 at 10:27 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Sorry. I don't understand. What do you mean by POST?  
> This?
> 
> curl -XPOST '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '{  
> "query": {  
> "filtered" : {  
> "query" : {  
> "query\_string" : {  
> "query" : "some query string here"  
> }  
> },  
> "filter" : {  
> "term" : { "user" : "kimchy" }  
> }  
> }  
> }  
> }  
> '
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 janv. 2013 à 04:06, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) a écrit :
> 
> I found a partial answer. one can pass complete query in GET source parameter. But the query I generate (with facet, facet filters + filtered (based on selected facet values) query can rather long. I would be more comfortable passing it as post parameter. I tried post with source parameter but unfortunately it does not work:
> 
> {"error":"SearchPhaseExecutionException[Failed to execute phase [query\_fetch], total failure; shardFailures {[pguRRu2dTzKk\_AMMcUO32w][award][0]: SearchParseException[[award][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@61f0ab21]; }]","status":500}
> 
> On Wednesday, January 30, 2013 9:43:43 PM UTC-5, AlexR wrote:  
> Hello,
> 
> For complete functionality, UI framework I use needs query be passed in POST parameters rather than body. Is there any way I can pass complete query I would normally pass in the body in POST parameter.
> 
> Using GET and URI is not an option - I need full query DSL
> 
> Thank you,  
> Alex
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [January 31, 2013, 6:03pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/6 "2013-01-31T18:03:33Z")

</div>

I am already doing it with GET and source parameter and it works well. One  
huge benefit is that size and start (and hopefully sort but have not tested  
it yet) url parameters override whatever is in source={...} - big help  
integrating with UI components that manage paging and generate these http  
parameters

Now the problem is that for all practical purposes uri length is limited to  
2000 characters so GET may very well fail with bigger queries (as I said  
query with facet based "filtered", facets themselves, filters.... can get  
pretty long plus of course url-encoding of all spaces and {} )

I wish the same functionality were available via POST. Couldn't ES check  
encoding in POST header and if it is \*application/x-www-form-urlencoded \*just  
extract encoded parameters and use source parameter just like it does with  
GET?

Do you think I should put an enhancement request into Git?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Kelsey\_Hamer](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Kelsey\_Hamer](https://discuss.elastic.co/u/Kelsey_Hamer)\
**Post date:** [November 26, 2014, 10:54pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/7 "2014-11-26T22:54:33Z")

</div>

I had a similar issue.  
I manged to get the parameters from the post by doing:

@Override

public void handleRequest(final RestRequest request, final RestChannel  
channel) {

Map\<String,String\> params = new HashMap\<String, String\>();  
RestUtils.decodeQueryString(request.content().toUtf8(), 0, params);  
String paramValue = params.get("parameter");

//DO SOMETHING

}

Notice that the json query you want to pass in doesn't need to be encoded  
on the client side (with an Http.GET it needs to be)

Hope that helps

On Thursday, January 31, 2013 10:03:33 AM UTC-8, AlexR wrote:

> I am already doing it with GET and source parameter and it works well. One  
> huge benefit is that size and start (and hopefully sort but have not tested  
> it yet) url parameters override whatever is in source={...} - big help  
> integrating with UI components that manage paging and generate these http  
> parameters
> 
> Now the problem is that for all practical purposes uri length is limited  
> to 2000 characters so GET may very well fail with bigger queries (as I said  
> query with facet based "filtered", facets themselves, filters.... can get  
> pretty long plus of course url-encoding of all spaces and {} )
> 
> I wish the same functionality were available via POST. Couldn't ES check  
> encoding in POST header and if it is \*application/x-www-form-urlencoded \*just  
> extract encoded parameters and use source parameter just like it does with  
> GET?
> 
> Do you think I should put an enhancement request into Git?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [November 27, 2014, 12:00am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/8 "2014-11-27T00:00:55Z")

</div>

Thanks Kelsey that could be useful. I managed to get my UI framework  
(ExtJS) to play better with POST so I am not dependent on having to use GET  
any more

On Wed Nov 26 2014 at 5:54:43 PM Kelsey Hamer [kelsey.hamer@gmail.com](mailto:kelsey.hamer@gmail.com)  
wrote:

> I had a similar issue.  
> I manged to get the parameters from the post by doing:
> 
> @Override
> 
> public void handleRequest(final RestRequest request, final RestChannel  
> channel) {
> 
> Map\<String,String\> params = new HashMap\<String, String\>();  
> RestUtils.decodeQueryString(request.content().toUtf8(), 0, params);  
> String paramValue = params.get("parameter");
> 
> //DO SOMETHING
> 
> }
> 
> Notice that the json query you want to pass in doesn't need to be encoded  
> on the client side (with an Http.GET it needs to be)
> 
> Hope that helps
> 
> On Thursday, January 31, 2013 10:03:33 AM UTC-8, AlexR wrote:
> 
> > I am already doing it with GET and source parameter and it works well.  
> > One huge benefit is that size and start (and hopefully sort but have not  
> > tested it yet) url parameters override whatever is in source={...} - big  
> > help integrating with UI components that manage paging and generate these  
> > http parameters
> > 
> > Now the problem is that for all practical purposes uri length is limited  
> > to 2000 characters so GET may very well fail with bigger queries (as I said  
> > query with facet based "filtered", facets themselves, filters.... can get  
> > pretty long plus of course url-encoding of all spaces and {} )
> > 
> > I wish the same functionality were available via POST. Couldn't ES check  
> > encoding in POST header and if it is \*application/x-www-form-urlencoded \*just  
> > extract encoded parameters and use source parameter just like it does with  
> > GET?
> > 
> > Do you think I should put an enhancement request into Git?
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/tDmS4ABPag0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/tDmS4ABPag0/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bddfebfc-519f-4320-b8aa-024849ae0c31%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAY7rMS4sh%2BDHF%2BYTCOs6OT3Q7iZfCDOR2o\_ct9adqP7dPTH%3Dw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAY7rMS4sh%2BDHF%2BYTCOs6OT3Q7iZfCDOR2o_ct9adqP7dPTH%3Dw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:47am UTC](https://discuss.elastic.co/t/is-there-any-way-to-pass-search-query-in-post-parameter-rather-than-body/10563/9 "2017-07-06T00:47:24Z")

</div>


