如何在使用perl语言的新elasticsearch中使用聚合框架

svmlkihl  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(639)

我正在从事elasticsearch,我必须进行聚合(即用于汇总我们的数据),我在下面分享了我的代码。。。。
代码:

my $portal_es = Search::Elasticsearch->new(nodes => [$es_ip.':'.$es_port],request_timeout => 180); 
    my $result = $portal_es->scroll_helper(index => 10002500,size =>"10000", params=>{rest_total_hits_as_int =>true},{
      #"size": 0,
     aggs=> {
        "my-agg-name"=> {
          terms=> {
            field=> "tcode"
          }
        }
      }
});

我有以下错误

[Param]**Expecting a HASH ref or a list of key-value pairs, called from sub Search::Elasticsearch::Role::Client::Direct::Main::scroll_helper at /home/prity/Desktop/BL_script/search_index_processor/aggregation.pl line 15. With vars: {'params' => ['index','10002500','size','10000','params',{'rest_total_hits_as_int' => 'true'},{'aggs' => {'my-agg-name' => {'terms' => {'field' => 'tcode'}}}}]}
pqwbnv8z

pqwbnv8z1#

参数列表中的数据结构可能已损坏。

my $result = $portal_es->scroll_helper(
   index  => 10002500,
   size   => "10000", 
   params => {
     rest_total_hits_as_int => 'true'
   },
   {                          # <---- here
     aggs => {
     # ...

您正在将键/值对的列表传递到 scroll_helper ,但后面还有一个额外的最后一个参数 params . 这是一个哈希引用 aggs 里面没有钥匙。
打开 use warnings 您将得到一个警告,指出您的数据结构缺少一个值(因为hashref将字符串化为一个键)。
你可能不该关闭hashref params 打开了一个新的。但这只是一个猜测,我不知道这个方法期望得到什么。

相关问题