我正在使用ELASTICSEARCH的Head插件来运行查询。 我想在表中转换查询的输出。
我需要的部分只是“命中”对象数组 其中列是我在查询中指定的字段: “http.date”, “src_shift”, “@时间戳”, “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"]}},...
答案 0 :(得分:3)
在头部插件中,在“任意请求”选项卡上,您可以使用“查询”部分下方的“结果转换器”部分。默认情况下,它返回整个JSON响应。
您可以修改它并按摩响应以返回您想要的任何内容。在您的情况下,如果您使用下面的代码替换默认的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"
...
答案 1 :(得分:1)
Kibana中有一个名为tabify
的实用程序,它将ElasticSearch结果转换为表格形式。您可以在此处找到其实施:https://github.com/elastic/kibana/blob/master/src/ui/public/agg_response/tabify/tabify.js