0

在下面的部分中,我需要为每个部分选择输出的第一个条目,这又是 ElasticSearch 索引的名称。

例如 nprod@n_docs、platform-api-stage、nprod@janeuk_classic、nprod@deista.com@1

所以我知道它们介于字符模式之间,例如

{ "

和一个

:{“设置”:{

那么我的脚本会是什么样子来获取这些值,以便我可以将它们放到另一个文件中?

我的输出看起来像:

{
  "nprod@n_docs" : {
    "settings" : {
      "index.analysis.analyzer.rwn_text_analyzer.char_filter" : "html_strip",
      "index.analysis.analyzer.rwn_text_analyzer.language" : "English",
      "index.translog.disable_flush" : "false",
      "index.version.created" : "190199",
      "index.number_of_replicas" : "1",
      "index.number_of_shards" : "5",
      "index.analysis.analyzer.rwn_text_analyzer.type" : "snowball",
      "index.translog.flush_threshold_size" : "60",
      "index.translog.flush_threshold_period" : "",
      "index.translog.flush_threshold_ops" : "500"
    }
  },
  "platform-api-stage" : {
    "settings" : {
      "index.analysis.analyzer.api_edgeNGram.type" : "custom",
      "index.analysis.analyzer.api_edgeNGram.filter.0" : "api_nGram",
      "index.analysis.filter.api_nGram.max_gram" : "50",
      "index.analysis.analyzer.api_edgeNGram.filter.1" : "lowercase",
      "index.analysis.analyzer.api_path.type" : "custom",
      "index.analysis.analyzer.api_path.tokenizer" : "path_hierarchy",
      "index.analysis.filter.api_nGram.min_gram" : "2",
      "index.analysis.filter.api_nGram.type" : "edgeNGram",
      "index.analysis.analyzer.api_edgeNGram.tokenizer" : "standard",
      "index.analysis.filter.api_nGram.side" : "front",
      "index.analysis.analyzer.api_path.filter.0" : "lowercase",
      "index.number_of_shards" : "5",
      "index.number_of_replicas" : "1",
      "index.version.created" : "200599"
    }
  },
  "nprod@janeuk_classic" : {
    "settings" : {
      "index.analysis.analyzer.n_text_analyzer.language" : "English",
      "index.translog.disable_flush" : "false",
      "index.version.created" : "190199",
      "index.number_of_replicas" : "1",
      "index.number_of_shards" : "5",
      "index.analysis.analyzer.n_text_analyzer.char_filter" : "html_strip",
      "index.analysis.analyzer.n_text_analyzer.type" : "snowball",
      "index.translog.flush_threshold_size" : "60",
      "index.translog.flush_threshold_period" : "",
      "index.translog.flush_threshold_ops" : "500"
    }
  },
  "nprod@delista.com@1" : {
    "settings" : {
      "index.analysis.analyzer.n_text_analyzer.language" : "English",
      "index.translog.disable_flush" : "false",
      "index.version.created" : "191199",
      "index.number_of_replicas" : "1",
      "index.number_of_shards" : "5",
      "index.analysis.analyzer.n_text_analyzer.char_filter" : "html_strip",
      "index.analysis.analyzer.n_text_analyzer.type" : "snowball",
      "index.translog.flush_threshold_size" : "60",
      "index.translog.flush_threshold_period" : "",
      "index.translog.flush_threshold_ops" : "500"
    }
  },
4

1 回答 1

3

那是JSON。读取数据并使用JSON::XS对其进行解析。

use JSON::XS qw( decode_json );

my $file;
{ 
   open(my $fh, '<:raw', $qfn)
      or die("Can't open \"$qfn\": $!\n");
   local $/;
   $file = <$fh>;
}

my $data = decode_json($file);

然后,只需遍历树以获取所需的信息。

my @index_names = keys(%$data);
于 2013-03-22T20:49:45.813 回答