【发布时间】:2015-10-14 06:27:49
【问题描述】:
我使用以下代码 sn-p 向 Elasticsearch 进行了查询:
$ua = LWP::UserAgent->new;
$server_endpoint = 'http://localhost:9200/index/type/_mapping?pretty=true';
$resp = $ua->get( $server_endpoint );
$myResults = $resp->content();
$decoded = JSON::XS::decode_json( $myResults );
这是请求打印的内容(如果我在解码之前打印出 $myResults;如果您只是在浏览器中输入它也可以):
{"index" : {
"mappings" : {
"type" : {
"properties" : {
"@timestamp" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"@version" : {
"type" : "string"
},
"FIELD1" : {
"type" : "long"
},
"FIELD2" : {
"type" : "double"
},
"FIELD3" : {
"type" : "string"
},
"FIELD4" : {
"type" : "string"
},
"FIELD5" : {
"type" : "double"
},
...
"FIELDN" : {
"type" : "string"
}
}
}
}}}
我在这里要做的是访问字段的名称。通过执行以下操作,我可以获取存储在其中的内容的名称:
print "$decoded->{ \"index\" }{ \"mappings\" }{ \"type\" }{ \"properties\" }{ \"FIELD1\" }{ \"type\" }";
但到目前为止,我无法打印出“FIELD1”。我已经尝试打印出该类型的所有除了,但它只显示 HASH(0x7ff60b345978)。
任何帮助将不胜感激!
谢谢
【问题讨论】:
-
FIELD1是一个哈希引用 -
对。我如何访问它?
-
您刚刚访问了它。如果您打印一个哈希引用,它将打印为
HASH(0x7ff60b345978)我不确定您所说的"print out everything *except* for type"是什么意思。您可以使用keys关键字打印散列的键。请参阅perldoc.perl.org/functions/keys.html