Created
September 29, 2023 10:30
-
-
Save willsheppard/d54d89c87f1ff6cc9d2b8c70b9d71962 to your computer and use it in GitHub Desktop.
ElasticSearch example query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper::Concise; | |
use Search::Elasticsearch; | |
my $ekk = Search::Elasticsearch->new( | |
client => '7_0::Direct', | |
nodes => [ 'https://opensearch.example.com/', ], | |
send_get_body_as => 'POST', | |
$ENV{USE_EKK_PROXY} ? (handle_args => { https_proxy => $ENV{USE_EKK_PROXY} }) : (), | |
); | |
my $results = $ekk->search( | |
body => { | |
"size" => 500, | |
"sort" => [ | |
{ | |
"timestamp" => { | |
"order" => "desc", | |
"unmapped_type" => "boolean" | |
} | |
} | |
], | |
"aggs" => { | |
"2" => { | |
"date_histogram" => { | |
"field" => "timestamp", | |
"calendar_interval" => "1d", | |
"time_zone" => "Europe/London", | |
"min_doc_count" => 1 | |
} | |
} | |
}, | |
"stored_fields" => ["*"], | |
"script_fields" => {}, | |
"docvalue_fields" => [ | |
{ | |
"field" => "timestamp", | |
"format" => "date_time" | |
} | |
], | |
"_source" => { | |
"excludes" => [] | |
}, | |
"query" => { | |
"bool" => { | |
"must" => [], | |
"filter" => [ | |
{ | |
"match_all" => {} | |
}, | |
{ | |
"match_phrase" => { | |
"foo_field" => "bar_value" | |
} | |
}, | |
{ | |
"range" => { | |
"timestamp" => { | |
"gte" => "2023-06-28T12:04:15.943Z", | |
"lte" => "2023-09-28T12:04:15.943Z", | |
"format" => "strict_date_optional_time" | |
} | |
} | |
} | |
], | |
"should" => [], | |
"must_not" => [] | |
} | |
}, | |
"highlight" => { | |
"pre_tags" => ["\@opensearch-dashboards-highlighted-field\@"], | |
"post_tags" => ["\@/opensearch-dashboards-highlighted-field\@"], | |
"fields" => { | |
"*" => {} | |
}, | |
"fragment_size" => 2147483647 | |
} | |
} | |
); | |
print Dumper($results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment