Perl client: Cannot combine params and body?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Perl client: Cannot combine params and body?

Andrew Walker
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',
        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",
                        default_operator => "AND"
                    }
                }
            }
        }
    }
);

print Dumper($res);


The generated curl is:

# Request to: https://service.host.com:443/api/es/a_path
curl -XGET 'http://localhost:9200/_search?api_key=API_KEY&pretty=1' -d '
{
   "query" : {
      "bool" : {
         "must" : {
            "query_string" : {
               "query" : "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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b990961c-a129-4cd0-b1e0-46f33f86c4ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Perl client: Cannot combine params and body?

Andrew Walker
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 => '<a href="http://service.host.com" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fservice.host.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF3qcXJ1QeSzfXn6t3oHz1uM6RUoA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fservice.host.com\46sa\75D\46sntz\0751\46usg\75AFQjCNF3qcXJ1QeSzfXn6t3oHz1uM6RUoA';return true;">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 => "<a href="http://thisisasitethatdoesntexist.com" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fthisisasitethatdoesntexist.com\46sa\75D\46sntz\0751\46usg\75AFQjCNEwmNXYZ0hiJpDp9La2ot2w_w-Z8g';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fthisisasitethatdoesntexist.com\46sa\75D\46sntz\0751\46usg\75AFQjCNEwmNXYZ0hiJpDp9La2ot2w_w-Z8g';return true;">thisisasitethatdoesntexist.com",
                        default_operator => "AND"
                    }
                }
            }
        }
    }
);

print Dumper($res);


The generated curl is:

# Request to: <a href="https://service.host.com:443/api/es/a_path" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fservice.host.com%3A443%2Fapi%2Fes%2Fa_path\46sa\75D\46sntz\0751\46usg\75AFQjCNH5l9i7vPeDfcFN_B36ZeqT_kuQXA';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fservice.host.com%3A443%2Fapi%2Fes%2Fa_path\46sa\75D\46sntz\0751\46usg\75AFQjCNH5l9i7vPeDfcFN_B36ZeqT_kuQXA';return true;">https://service.host.com:443/api/es/a_path
curl -XGET '<a href="http://localhost:9200/_search?api_key=API_KEY&amp;pretty=1" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A9200%2F_search%3Fapi_key%3DAPI_KEY%26pretty%3D1\46sa\75D\46sntz\0751\46usg\75AFQjCNEyAj0msFLQ2Q3dxRi9GzBJR_Vy8g';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A9200%2F_search%3Fapi_key%3DAPI_KEY%26pretty%3D1\46sa\75D\46sntz\0751\46usg\75AFQjCNEyAj0msFLQ2Q3dxRi9GzBJR_Vy8g';return true;">http://localhost:9200/_search?api_key=API_KEY&pretty=1' -d '
{
   "query" : {
      "bool" : {
         "must" : {
            "query_string" : {
               "query" : "<a href="http://thisisasitethatdoesntexist.com" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fthisisasitethatdoesntexist.com\46sa\75D\46sntz\0751\46usg\75AFQjCNEwmNXYZ0hiJpDp9La2ot2w_w-Z8g';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fthisisasitethatdoesntexist.com\46sa\75D\46sntz\0751\46usg\75AFQjCNEwmNXYZ0hiJpDp9La2ot2w_w-Z8g';return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/305579f6-9b50-4d0b-a678-510400cdd78e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Perl client: Cannot combine params and body?

Clinton Gormley-2
In reply to this post by Andrew Walker
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 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 [hidden email].
To view this discussion on the web visit 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.
Reply | Threaded
Open this post in threaded view
|

Re: Perl client: Cannot combine params and body?

Andrew Walker
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 <a href="https://github.com/elasticsearch/elasticsearch-perl/issues" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Felasticsearch%2Felasticsearch-perl%2Fissues\46sa\75D\46sntz\0751\46usg\75AFQjCNF5w6Fm3uQSV4rRudryLZEJRO2e5w';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Felasticsearch%2Felasticsearch-perl%2Fissues\46sa\75D\46sntz\0751\46usg\75AFQjCNF5w6Fm3uQSV4rRudryLZEJRO2e5w';return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7c649cb3-f934-4f74-bc74-bf5eedf22bb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Perl client: Cannot combine params and body?

Andrew Walker
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 <a href="https://github.com/elasticsearch/elasticsearch-perl/issues" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Felasticsearch%2Felasticsearch-perl%2Fissues\46sa\75D\46sntz\0751\46usg\75AFQjCNF5w6Fm3uQSV4rRudryLZEJRO2e5w';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Felasticsearch%2Felasticsearch-perl%2Fissues\46sa\75D\46sntz\0751\46usg\75AFQjCNF5w6Fm3uQSV4rRudryLZEJRO2e5w';return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9be4fff4-537a-4370-9427-1ac903af18a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.