Elasticsearch使用Perl LWP模块批量索引

时间:2015-08-07 13:27:07

标签: elasticsearch

以下是向批量发送请求的子例程 它将输入作为json并输出结果

 sub BulkJSON(){
                    my $json=@_[1];
                    #$id = lc $id; # Convert to lowercase as Elastic doesn't support uppercase ids
                    my $uri = $base_url.'/_bulk';
                    my $req = HTTP::Request->new( 'POST', $uri );
                    $req->header( 'Content-Type' => 'application/json' );
                    $req->content($json);

                    my $browser = LWP::UserAgent->new;
                    my $response = $browser->request($req);

                    $html = $response->content()."\n";

                    return "$html";
                } 

0 个答案:

没有答案