使用Search :: Elasticsearch时如何设置HTTP User-Agent?

时间:2015-02-23 17:46:40

标签: perl elasticsearch

我使用Search::Elasticsearch来查询MetaCPAN

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        => $size,
  body        => {
    fields => [qw(author archive date)],
    query  => { range => { date => { gte => $date } } },
  },
);

这可行,但我想将HTTP User-Agent标头设置为自定义值,以便在出现问题时可以识别我的请求。我如何使用Search :: Elasticsearch?

执行此操作

1 个答案:

答案 0 :(得分:4)

您可以使用handle_args将参数传递给handle构造函数。因此,对于默认HTTP::Tiny,您可以使用agent

my $es = Search::Elasticsearch->new(
  cxn_pool => 'Static::NoPing',
  nodes    => 'api.metacpan.org:80',
  handle_args => { agent => "youragent/0.1" },
);