0

我正在使用 ElasticSearch GET 来获取仪表板的 json 文件:例如:http://ES_IP:9200/kibana-int/dashboard/my_Dashboard/

这会返回一个 json 文件,例如:

{"_index":"kibana-int","_type":"dashboard","_id":"my_Dashboard","_version":5,"found":true,"_source":{ "user":"guest", "group":"guest", "title":"my_Dashboard", "dashboard":"{ \"title\": \"My Dashboard\", \"services\": { \"query\": { \"list\": { \"0\": { \"id\": 0, \"type\": \"lucene\", \"query\": \"type:dh AND severity:ERROR AND (response.baseUrl:\"/rm/recordings/*\" OR request.baseUrl:\"/rm/recordings/*\")\", \"alias\": \"DH errors rcc\",.......

这是我需要你帮助的地方,我怎样才能获得键“仪表板”的值,但在键/val 对中没有转义的 '\' 字符不会影响作为值一部分的转义符?

我需要的输出应该是这样的:

{ "title": "My Dashboard", "services": { "query": { "list": { "0": { "id": 0, "type": "lucene", "query": "type:dh AND severity:ERROR AND (response.baseUrl:\"/rm/recordings/*\" OR request.baseUrl:\"/rm/recordings/*\")", "alias": "DH errors rcc",.......

注意在查询键中,在它的值中,有一些不应该受到影响的\",因为它们是值的一部分。

我需要该输出,然后在我拥有的某个 bash 脚本中用 jq 解析该 json。

ElasticSearch api 是否有一些过滤器来为我提供该输出?或者你知道另一种外部方法来获得我需要的东西吗?

非常感谢您的帮助。

4

1 回答 1

0

fromjson是你的朋友。例如:

def data: {
  "_index": "kibana-int",
  "_type": "dashboard",
  "_id": "my_Dashboard",
  "_version": 5,
  "found": true,
  "_source": {
    "user": "guest",
    "group": "guest",
    "title": "my_Dashboard",
    "dashboard": "{ \"title\": \"My Dashboard\", \"services\": { \"query\": { \"list\": { \"0\": \"foobar\" }}}}"
  }
};

data | ._source.dashboard | fromjson

输出:

$ jq -n -f elastic.jq
{
  "title": "My Dashboard",
  "services": {
    "query": {
      "list": {
        "0": "foobar"
      }
    }
  }
}
于 2015-08-23T17:11:57.050 回答