我正在使用 ELASTICSEARCH 的 Head 插件来运行查询。
我想在表中转换查询的输出。

我需要的部分只是“命中”对象数组
其中列是我在查询中指定的字段:
"http.date","src_shift","@timestamp","src_tz"。

有什么工具或插件可以做到这一点吗?

下面是查询的简要输出:

"took": 2418,
"timed_out": false,
"_shards": {
    "total": 3503,
    "successful": 3503,
    "failed": 0
},
"hits": {
    "total": 2524,"max_score": 9.194927,"hits": [
        {
            "_index": "$002555","_type": "pcap","_id": "AVAJJphp2MeWtoWCbQYG","_score": 9.194927,"fields": {
                "src_shift": [
                    1],"http.date": [
                    "Fri, 12 Jun 2015 22:40:54 GMT"],"@timestamp": [
                    1434147980397],"src_tz": [
                    "Europe/Warsaw"]}},{
            "_index": "$002555","_type": "pcap","_id": "AVAJJphp2MeWtoWCbQYH","_score": 9.194927,"fields": {
                "src_shift": [
                    1],"http.date": [
                    "Fri, 12 Jun 2015 22:40:54 GMT"],"@timestamp": [
                    1434147980397],"src_tz": [
                    "Europe/Warsaw"]}},...

最佳答案

在 head 插件中,在 Any Request 选项卡上,您可以使用位于 Query 部分正下方的 Result Transformer 部分。默认情况下,它返回整个 JSON 响应。

json - 如何在表中转换 Elasticsearch json 输出?-LMLPHP

您可以修改它并按摩响应以返回您想要的任何内容。在你的情况下,如果你用下面的代码替换默认的 return root; ,你会得到你想要的:

return root.hits.hits.map(function(hit) {
    var values = [];
    for (var field in hit.fields) {
        values.push(hit.fields[field]);
    }
    return values.join(",");
});

输出应该是
1,"Fri, 12 Jun 2015 22:40:54 GMT",1434147980397,"Europe/Warsaw"
1,"Fri, 12 Jun 2015 22:40:54 GMT",1434147980397,"Europe/Warsaw"
...

关于json - 如何在表中转换 Elasticsearch json 输出?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32920932/

10-12 12:39
查看更多