gpt4 book ai didi

perl - 如何在MetaCPAN上进行滚动搜索?

转载 作者:行者123 更新时间:2023-12-03 02:08:49 26 4
gpt4 key购买 nike

我正在尝试将this script转换为使用新的Elasticsearch official client而不是较旧的(现在已不推荐使用)ElasticSearch.pm,但是我无法使滚动搜索起作用。这是我得到的:

#! /usr/bin/perl

use strict;
use warnings;
use 5.010;

use Elasticsearch ();
use Elasticsearch::Scroll ();

my $es = Elasticsearch->new(
nodes => 'http://api.metacpan.org:80',
cxn => 'NetCurl',
cxn_pool => 'Static::NoPing',
#log_to => 'Stderr',
#trace_to => 'Stderr',
);

say 'Getting all results at once works:';
my $results = $es->search(
index => 'v0',
type => 'release',
body => {
filter => { range => { date => { gte => '2013-11-28T00:00:00.000Z' } } },
fields => [qw(author archive date)],
},
);

foreach my $hit (@{ $results->{hits}{hits} }) {
my $field = $hit->{fields};
say "@$field{qw(date author archive)}";
}

say "\nUsing a scrolled search does not work:";
my $scroller = Elasticsearch::Scroll->new(
es => $es,
index => 'v0',
search_type => 'scan',
size => 100,
type => 'release',
body => {
filter => { range => { date => { gte => '2013-11-28T00:00:00.000Z' } } },
fields => [qw(author archive date)],
},
);

while (my $hit = $scroller->next) {
my $field = $hit->{fields};
say "@$field{qw(date author archive)}";
} # end while $hit

第一次搜索时,我只是将所有结果都放在一个块中,效果很好。但是第二次搜索(我试图在结果中滚动)产生了:
Using a scrolled search does not work:
[Request] ** [http://api.metacpan.org:80]-[500]
ActionRequestValidationException[Validation Failed: 1: scrollId is missing;],
called from sub Elasticsearch::Transport::try {...}
at .../Try/Tiny.pm line 83. With vars: {'body' =>
'ActionRequestValidationException[Validation Failed: 1: scrollId is missing;]',
'request' => {'path' => '/_search/scroll','serialize' => 'std',
'body' => 'c2Nhbjs1OzE3MjU0NjM2MjowakFELUU3VFFibTJIZW1ibUo0SUdROzE3MjU0NjM2NDowakFELUU3VFFibTJIZW1ibUo0SUdROzE3MjU0NjM2MTowakFELUU3VFFibTJIZW1ibUo0SUdROzE3MjU0NjM2MDowakFELUU3VFFibTJIZW1ibUo0SUdROzE3MjU0NjM2MzowakFELUU3VFFibTJIZW1ibUo0SUdROzE7dG90YWxfaGl0czoxNDQ7',
'method' => 'GET','qs' => {'scroll' => '1m'},'ignore' => [],
'mime_type' => 'application/json'},'status_code' => 500}

我究竟做错了什么?我正在使用Elasticsearch 0.75,Elasticsearch-Cxn-NetCurl 0.02和Perl 5.18.1。

最佳答案

我终于把它与newer Search::Elasticsearch official client一起使用了。这是简短的版本:

#! /usr/bin/perl

use strict;
use warnings;
use 5.010;

use Search::Elasticsearch ();

my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => 'api.metacpan.org:80',
);

my $scroller = $es->scroll_helper(
index => 'v0',
type => 'release',
search_type => 'scan',
scroll => '2m',
size => 100,
body => {
fields => [qw(author archive date)],
query => { range => { date => { gte => '2015-02-01T00:00:00.000Z' } } },
},
);

while (my $hit = $scroller->next) {
my $field = $hit->{fields};
say "@$field{qw(date author archive)}";
} # end while $hit

请注意,当您进行滚动搜索时,记录不会排序。我结束了将记录转储到临时数据库中并在本地对其进行排序的工作。 updated script在GitHub上。

关于perl - 如何在MetaCPAN上进行滚动搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20294182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com