从hashie中检索值:mash在另一个数组中

时间:2013-02-06 20:20:00

标签: ruby hash

我正在尝试从elasticsearch返回的结果中提取值。 返回的结果集是一个数组,数组中的对象是Hashie:Mash。

结果集如下所示:

#<Hashie::Mash @fields=#<Hashie::Mash latency=[8.0] response_code=[200.0] response_time=[744.0] sampler_label=["globalnav"] success=[1] my_id=["specnn1"]> @message="globalnav,1,744,200,8,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.472Z" @type="jm_type" _id="5ACJI7NqRvCK_THBiRszrQ">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[8.0] response_code=[200.0] response_time=[801.0] sampler_label=["globalnav"] success=[1] my_id=["specnn1"]> @message="globalnav,1,801,200,8,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.489Z" @type="jm_type" _id="Mzpz30H3Qf6wLxx_IAO8uQ">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[8.0] response_code=[200.0] response_time=[10.0] sampler_label=["homepage"] success=[1] my_id=["specnn1"]> @message="homepage,1,10,200,8,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:28.115Z" @type="jm_type" _id="vN8t39UmQwy9PxhRGKU5uQ">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[8.0] response_code=[200.0] response_time=[9.0] sampler_label=["homepage"] success=[1] my_id=["specnn1"]> @message="homepage,1,9,200,8,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:28.196Z" @type="jm_type" _id="mMkV4sqwTEqU6OiY5-q3JA">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[10.0] response_code=[200.0] response_time=[747.0] sampler_label=["globalnav"] success=[1] my_id=["specnn1"]> @message="globalnav,1,747,200,10,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.475Z" @type="jm_type" _id="LVZaHrExS7Cy8l9ndCBGIA">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[17.0] response_code=[200.0] response_time=[25.0] sampler_label=["random_content"] success=[1] my_id=["specnn1"]> @message="random_content,1,25,200,17,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:28.185Z" @type="jm_type" _id="cLaYGsA_T9e2F70NbvoSqQ">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[800.0] response_code=[200.0] response_time=[808.0] sampler_label=["random_content"] success=[1] my_id=["specnn1"]> @message="random_content,1,808,200,800,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.465Z" @type="jm_type" _id="OFbQcHyATDS2l-IWxltIug">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[15.0] response_code=[200.0] response_time=[20.0] sampler_label=["homepage"] success=[1] my_id=["specnn1"]> @message="homepage,1,20,200,15,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.467Z" @type="jm_type" _id="gdz3yDkTSyqgn-2S5yirEg">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[393.0] response_code=[200.0] response_time=[400.0] sampler_label=["random_content"] success=[1] my_id=["specnn1"]> @message="random_content,1,400,200,393,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.491Z" @type="jm_type" _id="5XGEVQzFS_S_OTLpD1KPfQ">
#<Hashie::Mash @fields=#<Hashie::Mash latency=[16.0] response_code=[200.0] response_time=[22.0] sampler_label=["random_content"] success=[1] my_id=["specnn1"]> @message="random_content,1,22,200,16,specnn1,\r" @source="file:///fqdn/ffw_spectrum.log" @source_host="xplda04.ieee.org" @source_path="/full/path/ffw_spectrum.log" @tags=["jm_type"] @timestamp="2013-02-04T20:47:12.504Z" @type="jm_type" _id="wi14pyNHRWaH6AK7874KiA">

我能够通过遍历数组然后循环遍历hasie并循环遍历数组然后获取hashie mash中的值来提取response_time。

使用ruby提取response_time值是否容易或有效?

1 个答案:

答案 0 :(得分:0)

array.map(&:response_time)正在做你想要达到的目标吗?