2013-03-22 107 views
0

在下面的部分中,我需要爲每個節選擇輸出的第一個條目,而每個節又是ElasticSearch索引的名稱。爲elasticsearch索引解析文本並獲取索引值

例如nprod @ n_docs,平臺的API級,nprod @ janeuk_classic,nprod @ delista.com @ 1

所以我知道他們是字符模式之間像

{「

:{ 「設置」:{

那麼我的腳本會如何抓取這些值,以便我可以將它們發送到另一個文件?

我的輸出看起來像:

{ 
    "[email protected]_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" 
    } 
    }, 
    "[email protected]_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" 
    } 
    }, 
    "[email protected]@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" 
    } 
    }, 
+2

請不要小聲 – LittleBobbyTables 2013-03-22 20:41:05

回答

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);