0

我正在尝试从 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并遍历数组来提取response_time,然后得到哈希mash中的值。

有没有一种简单或有效的方法来response_time使用红宝石提取价值?

4

1 回答 1

0

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

于 2013-02-06T22:42:31.813 回答