루트 수준으로 중첩 된 객체를 가져 :자바 스크립트는 내가 다음과 같습니다 JSON 객체를 가지고
{
"total": 298,
"max_score": 5.2472496,
"hits": [
{
"_index": "kafkajmx2",
"_type": "logs",
"_id": "AVo-VsUdponm9zQGYYS5",
"_score": 5.2472496,
"_source": {
"metric_value_number": 134,
"path": "/home/usrxxx/logstash-5.2.0/bin/jmxconf",
"@timestamp": "2017-02-14T20:35:58.266Z",
"metric_name": "IsrExpandsPerSec.Count",
"@version": "1",
"host": "localhost",
"metric_type": "ReplicaManager",
"metric_path": "node1.kafka.server:type=ReplicaManager,name=IsrExpandsPerSec.Count",
"type": null,
"metric_node": "node1.kafka.server"
}
},
{
"_index": "kafkajmx2",
"_type": "logs",
"_id": "AVo-V69Yponm9zQGYYwS",
"_score": 5.2472496,
"_source": {
"metric_value_number": 134,
"path": "/home/usrxxx/logstash-5.2.0/bin/jmxconf",
"@timestamp": "2017-02-14T20:36:58.216Z",
"metric_name": "IsrExpandsPerSec.Count",
"@version": "1",
"host": "localhost",
"metric_type": "ReplicaManager",
"metric_path": "node1.kafka.server:type=ReplicaManager,name=IsrExpandsPerSec.Count",
"type": null,
"metric_node": "node1.kafka.server"
}
}
]
}
제가하고 싶은 것은이 같은 모습에 루트 레벨로 _source
객체를 가져다 :
{
"metric_value_number": 134,
"path": "/home/usrxxx/logstash-5.2.0/bin/jmxconf",
"@timestamp": "2017-02-14T20:36:58.216Z",
"metric_name": "IsrExpandsPerSec.Count",
"@version": "1",
"host": "localhost",
"metric_type": "ReplicaManager",
"metric_path": "node1.kafka.server:type=ReplicaManager,name=IsrExpandsPerSec.Count",
"type": null,
"metric_node": "aesdp0101.kafka.server"
},
{
"metric_value_number": 134,
"path": "/home/usrxxx/logstash-5.2.0/bin/jmxconf",
"@timestamp": "2017-02-14T20:35:58.266Z",
"metric_name": "IsrExpandsPerSec.Count",
"@version": "1",
"host": "localhost",
"metric_type": "ReplicaManager",
"metric_path": "node1.kafka.server:type=ReplicaManager,name=IsrExpandsPerSec.Count",
"type": null,
"metric_node": "aesdp0101.kafka.server"
}
나는 기본적으로 자바 스크립트에서이 작업을 수행하는 방법을 잘 모르겠어요하거나이 방법을 수행하는 내가 해봤
뿐만 아니라이 작업을 수행하는 lodash의 방법은 ...있을 경우 만 나는라고 생각한다. _source
의이 코드에 영향을 줍니까?
var metricData = [];
for (var i=0; i < response.length; i++) {
metricData.push(response[i]._source);
console.log("metric data: ", metricData);
};
을 당신은 귀하의 질문에 아무 곳이나 metricData''배열이 없습니다. – Lee
죄송합니다, 그 포함을 잊어 버렸습니다, 나는'var metricData = []'코드를 가지고 있습니다 ... 편집을했습니다 ... – user2061886
아래의 답변을보십시오. – Lee