首页 > 解决方案 > 如何从 kibana 获取 JSON?

问题描述

从 Kibana 仪表板中,我得到了这个 JSON。我需要在我的网站中使用“消息”(这是我的脚本的结果),我该怎么做?

注意:脚本是logstash的输入,它被发送到elasticsearch,然后用Kibana可视化,这段代码来自kibana中的JSON部分。

  {
  "_index": "test",
  "_type": "doc",
  "_id": "l-RRWncBMkK0B15vMizO",
  "_version": 1,
  "_score": null,
  "_source": {
    "command": "sh -c /home/ubuntu/hello.sh",
    "host": "elk",
    "@version": "1",
    "message": "bin\nboot\ndev\netc\nhome\ninitrd.img\ninitrd.img.old\nlib\nlib64\nlost+found\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsnap\nsrv\nsys\ntmp\nusr\nvar\nvmlinuz\nvmlinuz.old\n",
    "@timestamp": "2021-01-31T21:20:06.716Z"
  },
  "fields": {
    "@timestamp": [
      "2021-01-31T21:20:06.716Z"
    ]
  },
  "sort": [
    1612128006716
  ]
}

标签: elasticsearchlogstashkibanaelk

解决方案


你的问题似乎不完整。但是,我假设,您正在尝试将事件从 Elasticsearch 访问到您的代码段。

您可以尝试点击 Elasticsearch api 来获取此 json,并访问消息字段。下面的例子:

**SYNTAX**
curl -XGET "<elasticsearch_ip>:<elasticsearchport(default is 9200)>/<index_name>/_search" -H 'Content-Type: application/json' -d'<query to fetch the index documents>'



**EXAMPLE** 
curl -XPOST "http://localhost:9200/test/_search" -H 'Content-Type: application/json' -d'{  "query": {    "match_all": {}  }}'

推荐阅读