elasticsearch 获取索引信息

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zhaoyangjian724/article/details/72965302
use  LWP::UserAgent;   
use  Encode;
use  Data::Dumper;
use  JSON;
use POSIX;
sub check_es {
my $SDATE = strftime("%Y.%m.%d",localtime());
my $ua = LWP::UserAgent->new;  
$ua->timeout(10);  
$ua->env_proxy;  
$ua->agent("Mozilla/8.0");  
#my $host = "http://10.5.100.232:9200/logstash-tlcb-2017.06.10/_search";  
my $host = "http://192.168.137.2:9200/twitter/_search";  
my $response = $ua->get($host);  
   $ua->default_headers;  
  if ($response->is_success) {  
#      print $response->decoded_content;  # or whatever  
      my $r=$response->decoded_content;
      my $r=encode_utf8($r);
      $hash = decode_json($r);
   }  
    else {  
    print  $response->status_line;  
} ;
my $count= $hash->{'hits'}{total};
return $count;
};
print check_es


C:\Users\TLCB\Desktop\elk\Elasticsearch Api>perl check_es.pl
1
C:\Users\TLCB\Desktop\elk\Elasticsearch Api>


在创建一个索引:

C:\Users\TLCB\Desktop\elk\Elasticsearch Api>perl check_es.pl
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hit
s":{"total":2,"max_score":1.0,"hits":[{"_index":"twitter","_type":"tweet","_id":
"2","_score":1.0,"_source":{"post_date":"2009-11-15T14:12:12","user":"kimchy","m
essage":"trying out Elasticsearch999999"}},{"_index":"twitter","_type":"tweet","
_id":"1","_score":1.0,"_source":{"post_date":"2009-11-15T14:12:12","user":"kimch
y","message":"trying out Elasticsearch999999"}}]}}
2

展开阅读全文

没有更多推荐了,返回首页