# Perl client: Cannot combine params and body?

**URL:** <https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671>\
**Category:** Elasticsearch\
**Created:** [January 15, 2015, 8:44pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671 "2015-01-15T20:44:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Walker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_walker/32/976_2.png) [@Andrew\_Walker](https://discuss.elastic.co/u/Andrew_Walker)\
**Post date:** [January 15, 2015, 8:44pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/1 "2015-01-15T20:44:11Z")

</div>

I have a remote node that I am attempting to connect to that requires an  
api key as a URL parameter in addition to the body in order to get it to  
work.

The code is as follows:

#!/usr/bin/perl  
use v5.14;  
use warnings;  
use Search::Elasticsearch;  
use Data::Dumper;

my $API\_KEY='API\_KEY';

my $ES = Search::Elasticsearch-\>new(  
cxn\_pool =\> 'Static::NoPing',  
nodes =\> [{  
scheme =\> 'https',  
host =\> '[service.host.com](http://service.host.com)',  
port =\> 443,  
path =\> '/api/es/a\_path',  
}],  
#send\_get\_body\_as =\> 'POST',  
trace\_to =\> 'Stdout',  
log\_to =\> 'Stdout',  
);

my $res = $ES-\>search(  
params =\> {  
api\_key =\> $API\_KEY,  
},  
body =\> {  
query =\> {  
bool =\> {  
must =\> {  
query\_string =\> {  
default\_field =\> "\_all",  
query =\> "[thisisasitethatdoesntexist.com](http://thisisasitethatdoesntexist.com)",  
default\_operator =\> "AND"  
}  
}  
}  
}  
}  
);

print Dumper($res);

The generated curl is:

# Request to: [https://service.host.com:443/api/es/a\_path](https://service.host.com:443/api/es/a_path)

curl -XGET '[http://localhost:9200/\_search?api\_key=API\_KEY&pretty=1](http://localhost:9200/_search?api_key=API_KEY&pretty=1)' -d '  
{  
"query" : {  
"bool" : {  
"must" : {  
"query\_string" : {  
"query" : "[thisisasitethatdoesntexist.com](http://thisisasitethatdoesntexist.com)",  
"default\_field" : "\_all",  
"default\_operator" : "AND"  
}  
}  
}  
}  
}  
'

When I replace localhost and the path with the proper host and path and run  
the curl command directly from the command line, I get zero hits back,  
which is what I expect. If I run the above perl, however, I get many  
millions of results back, which is exactly the same as what I get when I  
remove the body from the curl query (-d ''). So it seems that the  
combination of params and body causes body to get eaten? I looked at the  
code, but I couldn't find where this might be happening. Any help?

--  
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/b990961c-a129-4cd0-b1e0-46f33f86c4ff%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b990961c-a129-4cd0-b1e0-46f33f86c4ff%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Andrew\_Walker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_walker/32/976_2.png) [@Andrew\_Walker](https://discuss.elastic.co/u/Andrew_Walker)\
**Post date:** [January 21, 2015, 5:59pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/2 "2015-01-21T17:59:11Z")

</div>

Is there another mailing list I should be using, perhaps? I have still  
found no solution to this problem.

On Thursday, January 15, 2015 at 3:44:11 PM UTC-5, Andrew Walker wrote:

> I have a remote node that I am attempting to connect to that requires an  
> api key as a URL parameter in addition to the body in order to get it to  
> work.
> 
> The code is as follows:
> 
> #!/usr/bin/perl  
> use v5.14;  
> use warnings;  
> use Search::Elasticsearch;  
> use Data::Dumper;
> 
> my $API\_KEY='API\_KEY';
> 
> my $ES = Search::Elasticsearch-\>new(  
> cxn\_pool =\> 'Static::NoPing',  
> nodes =\> [{  
> scheme =\> 'https',  
> host =\> '[service.host.com](http://service.host.com)',  
> port =\> 443,  
> path =\> '/api/es/a\_path',  
> }],  
> #send\_get\_body\_as =\> 'POST',  
> trace\_to =\> 'Stdout',  
> log\_to =\> 'Stdout',  
> );
> 
> my $res = $ES-\>search(  
> params =\> {  
> api\_key =\> $API\_KEY,  
> },  
> body =\> {  
> query =\> {  
> bool =\> {  
> must =\> {  
> query\_string =\> {  
> default\_field =\> "\_all",  
> query =\> "[thisisasitethatdoesntexist.com](http://thisisasitethatdoesntexist.com)",  
> default\_operator =\> "AND"  
> }  
> }  
> }  
> }  
> }  
> );
> 
> print Dumper($res);
> 
> The generated curl is:
> 
> # Request to: [https://service.host.com:443/api/es/a\_path](https://service.host.com:443/api/es/a_path)
> 
> curl -XGET '[http://localhost:9200/\_search?api\_key=API\_KEY&pretty=1](http://localhost:9200/_search?api_key=API_KEY&pretty=1)' -d '  
> {  
> "query" : {  
> "bool" : {  
> "must" : {  
> "query\_string" : {  
> "query" : "[thisisasitethatdoesntexist.com](http://thisisasitethatdoesntexist.com)",  
> "default\_field" : "\_all",  
> "default\_operator" : "AND"  
> }  
> }  
> }  
> }  
> }  
> '
> 
> When I replace localhost and the path with the proper host and path and  
> run the curl command directly from the command line, I get zero hits back,  
> which is what I expect. If I run the above perl, however, I get many  
> millions of results back, which is exactly the same as what I get when I  
> remove the body from the curl query (-d ''). So it seems that the  
> combination of params and body causes body to get eaten? I looked at the  
> code, but I couldn't find where this might be happening. Any help?

--  
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/305579f6-9b50-4d0b-a678-510400cdd78e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/305579f6-9b50-4d0b-a678-510400cdd78e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [January 21, 2015, 6:17pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/3 "2015-01-21T18:17:00Z")

</div>

Hi Andrew

The code looks correct. You have send\_get\_body\_as POST commented out - I'm  
guessing that is the problem. Probably the service you're using does not  
allow GET requests with bodies.

I'd uncomment that and try again.

Ping me on [https://github.com/elasticsearch/elasticsearch-perl/issues](https://github.com/elasticsearch/elasticsearch-perl/issues) if  
you still can't get it working

clint

--  
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/CAPt3XKTabrFBQ992PgupZENM%3DeeFhmr%3D%3DS0Kvz5byk93DK-uEw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTabrFBQ992PgupZENM%3DeeFhmr%3D%3DS0Kvz5byk93DK-uEw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Andrew\_Walker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_walker/32/976_2.png) [@Andrew\_Walker](https://discuss.elastic.co/u/Andrew_Walker)\
**Post date:** [January 21, 2015, 6:41pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/4 "2015-01-21T18:41:39Z")

</div>

I forgot to mention that; it's commented out because the service I'm  
attempting to access refuses POST requests. I've been informed that this  
is a sort of low-hanging fruit security measure to prevent mutating methods.

On Wednesday, January 21, 2015 at 1:17:07 PM UTC-5, Clinton Gormley wrote:

> Hi Andrew
> 
> The code looks correct. You have send\_get\_body\_as POST commented out -  
> I'm guessing that is the problem. Probably the service you're using does  
> not allow GET requests with bodies.
> 
> I'd uncomment that and try again.
> 
> Ping me on [Issues · elastic/elasticsearch-perl · GitHub](https://github.com/elasticsearch/elasticsearch-perl/issues) if  
> you still can't get it working
> 
> clint

--  
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/7c649cb3-f934-4f74-bc74-bf5eedf22bb7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7c649cb3-f934-4f74-bc74-bf5eedf22bb7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Andrew\_Walker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_walker/32/976_2.png) [@Andrew\_Walker](https://discuss.elastic.co/u/Andrew_Walker)\
**Post date:** [January 21, 2015, 6:50pm UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/5 "2015-01-21T18:50:43Z")

</div>

I have submitted an issue. Thanks for your attention!

On Wednesday, January 21, 2015 at 1:41:39 PM UTC-5, Andrew Walker wrote:

> I forgot to mention that; it's commented out because the service I'm  
> attempting to access refuses POST requests. I've been informed that this  
> is a sort of low-hanging fruit security measure to prevent mutating methods.
> 
> On Wednesday, January 21, 2015 at 1:17:07 PM UTC-5, Clinton Gormley wrote:
> 
> > Hi Andrew
> > 
> > The code looks correct. You have send\_get\_body\_as POST commented out -  
> > I'm guessing that is the problem. Probably the service you're using does  
> > not allow GET requests with bodies.
> > 
> > I'd uncomment that and try again.
> > 
> > Ping me on [Issues · elastic/elasticsearch-perl · GitHub](https://github.com/elasticsearch/elasticsearch-perl/issues) if  
> > you still can't get it working
> > 
> > clint

--  
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/9be4fff4-537a-4370-9427-1ac903af18a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9be4fff4-537a-4370-9427-1ac903af18a4%40googlegroups.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:37am UTC](https://discuss.elastic.co/t/perl-client-cannot-combine-params-and-body/21671/6 "2017-07-06T00:37:30Z")

</div>


