如何在 vega-lite 中使用不同的 Elasticsearch 数据源叠加两个散点图?

问题描述 投票:0回答:2

我想叠加使用弹性搜索索引从不同数据源创建的两个散点图。我可以使用“图层”使用一个数据源来创建两个不同的图,但不能使用两个数据源来创建两个不同的图。我得到的错误是:

无法设置未定义的属性(设置“格式”)

我似乎不知道格式应该是什么。

我的代码结构如下所示:

{
      "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
        "layer": [
        {
            "data": {
            "url": {
                "index": "A",
                  "body": {
                    "size": 10000,
                    "_source": ["A_a", "A_b"],
                },
                "format": {"property": "hits.hits"}
              },
              "mark": "type": "circle"
              "encoding": {
              .
              .
              .
            }
          }
        },
        {
            "data": {
            "url": {
                "index": "B",
                  "body": {
                    "size": 10000,
                    "_source": ["B_a", "B_b"],
                },
                "format": {"property": "hits.hits"}
              },
              "mark": "type": "circle"
              "encoding": {
              .
              .
              .
            }
          }
        }
    ]
}


我已经尝试过改变

"format": {"property": "hits.hits"} 
"format": {"property": "hits.hits._source"} 

但这也没有解决任何问题。我还应该如何更改格式以适应两个数据源?

elasticsearch kibana vega-lite vega
2个回答
0
投票

用这个检查你的格式。在第二层中,我只是反转了 x/y。

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "layer": [
    {
      "data": {
        "url": "https://api.npoint.io/186ffeef12c2cb4fd764",
        "format": {"property": "hits.hits"}
      },
      "mark": "point",
      "encoding": {
        "x": {
          "field": "_source.property.b.c",
          "type": "ordinal",
          "axis": {"title": "A"}
        },
        "y": {
          "field": "_source.property.b.d",
          "type": "temporal",
          "axis": {"title": "B"}
        }
      }
    },
    {
      "data": {
        "url": "https://api.npoint.io/186ffeef12c2cb4fd764",
        "format": {"property": "hits.hits"}
      },
      "mark": "point",
      "encoding": {
        "x": {
          "field": "_source.property.b.d",
          "type": "ordinal",
          "axis": {"title": "A"}
        },
        "y": {
          "field": "_source.property.b.c",
          "type": "temporal",
          "axis": {"title": "B"}
        }
      }
    }
  ],
  "config": {}
}

数据:

{
   "hits":{
      "hits":[
         {
            "_id":"AcwtemoBAxKStAaIEnOV",
            "_type":"data",
            "_index":"my-index",
            "_score":1,
            "_source":{
               "property":{
                  "a":1,
                  "b":{
                     "c":1,
                     "d":5
                  }
               }
            }
         },
         {
            "_id":"BMwtemoBAxKStAaIEnOV",
            "_type":"data",
            "_index":"my-index",
            "_score":1,
            "_source":{
               "property":{
                  "a":2,
                  "b":{
                     "c":2,
                     "d":4
                  }
               }
            }
         }
      ],
      "total":1499,
      "max_score":1
   },
   "took":1,
   "_shards":{
      "total":5,
      "failed":0,
      "skipped":0,
      "successful":5
   },
   "timed_out":false
}

0
投票

我在分层时使用多个 Elasticsearch 索引作为数据源也面临着完全相同的问题。我只是想知道您是否找到了解决方案。如果您能更新此问题的当前状态,那将非常有帮助。预先感谢!

© www.soinside.com 2019 - 2024. All rights reserved.