当前位置: 首页 > 知识库问答 >
问题:

Altair 将数据保存到仪表板时出错

尚声
2023-03-14

嗨,大家好,我对牛郎星和vega的弹性搜索交互有问题。具体情况如下:我有一个索引模式,由一个38.8mb的数据以90k行的顺序生成。我想使用这个索引模式来创建一个可视化,让我可以基于两个值进行筛选。所以我的想法是,我想及时表示数据,并将此可视化插入kibana仪表板。我应该能够与可视化交互,并有可能根据插入的过滤器进行交互。我设法做到了这一点,详细地说,我设法用下面的部分代码创建了这个图:详细地说我们可以看到defsaveVegaLiteVis和从链接中获取的save对象,然后我们可以看到构建的图表,并按我的意愿工作。我想在数据增加的时候解决这个问题,因为我们的数据小于3 mb,所以在10k的量级上,我在可视化方面没有问题。

def saveVegaLiteVis(client, index, visName, altairChart, resultSize=100, timeField=True):
    chart_json = json.loads(altairChart.to_json())
    chart_json['data']['url'] = {
        "%context%": True,
        "index": index,
        "body": {
            "size": resultSize
        }
    }

    if timeField:
      chart_json['data']['url']['%timefield%'] = "timestamp"

    visState = {
      "type": "vega",
      "aggs": [],
      "params": {
        "spec": json.dumps(chart_json, sort_keys=True, indent=4, separators=(',', ': ')),
      },
      "title": visName
    }

    visSavedObject={
        "visualization" : {
          "title" : visName,
          "visState" : json.dumps(visState, sort_keys=True, indent=4, separators=(',', ': ')),
          "uiStateJSON" : "{}",
          "description" : "",
          "version" : 1,
          "kibanaSavedObjectMeta" : {
            "searchSourceJSON" : json.dumps({
              "query": {
                "language": "kuery",
                "query": ""
              },
              "filter": []
            }),
          }
        },
        "type" : "visualization",
        "references" : [ ],
        "migrationVersion" : {
          "visualization" : "7.7.0"
        },
        "updated_at" : datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
    }

    return client.index(index='.kibana',id='visualization:'+visName,body=visSavedObject)

def saveVegaVis(client, index, visName, altairChart, resultSize=100, timeField=True):
    chart_json = json.loads(altairChart.to_json())
    chart_json['spec']['data']['url'] = {
        "%context%": True,
        "index": index,
        "body": {
            "size": resultSize
        }
    }

    if timeField:
      chart_json['spec']['data']['url']['%timefield%'] = "timestamp"

    visState = {
      "type": "vega",
      "aggs": [],
      "params": {
        "spec": json.dumps(chart_json, sort_keys=True, indent=4, separators=(',', ': ')),
      },
      "title": visName
    }

    visSavedObject={
        "visualization" : {
          "title" : visName,
          "visState" : json.dumps(visState, sort_keys=True, indent=4, separators=(',', ': ')),
          "uiStateJSON" : "{}",
          "description" : "",
          "version" : 1,
          "kibanaSavedObjectMeta" : {
            "searchSourceJSON" : json.dumps({
              "query": {
                "language": "kuery",
                "query": ""
              },
              "filter": []
            }),
          }
        },
        "type" : "visualization",
        "references" : [ ],
        "migrationVersion" : {
          "visualization" : "7.7.0"
        },
        "updated_at" : datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
    }

    return client.index(index='.kibana',id='visualization:'+visName,body=visSavedObject)
def getDataBasedonIndex(index,idValue,es):
    es.indices.refresh(index=index)
    res = es.get(index=index, id=idValue)
    print(res['_source'])



input_dropdown = alt.binding_select(options=[[1,2,3,4,5],[4],[3],[1],[2],[5],[1,4,5],[3,4,5],[1,2,3,4],[1,3,5],[1,3,4],[1,2,5],[1,2,4],[1,2,3],[4,5],[4,2],[2,3],[1,2],[5,3],[3,4],[2,5],[1,4],[1,5],[1,2],[1,3]])
selection = alt.selection_single(fields=['NUMBER'], bind=input_dropdown, name='FIELD: ')

#dropdown
input_dropdown1 = alt.binding_select(options=[['M3','M4','M5','M6'],['M4'],['M3'],['M6'],['M5']])
selection1 = alt.selection_single(fields=['SHAPE TYPE'], bind=input_dropdown1, name='FIELD2: ')
#shape
selection_Operation= alt.selection_multi(fields=['NUMBER:N'],bind='legend')
shape_Operation = alt.condition(selection_Operation ,alt.Shape('NUMBER:N'), alt.value('lightgray'))

color = alt.condition(selection,alt.Color('SHAPE TYPE:N'), alt.value('lightgray'))

interaction1 = alt.selection_interval(bind='scales', on="[mousedown[event.altKey], mouseup] > mousemove", translate="[mousedown[event.altKey], mouseup] > mousemove!",
    zoom="wheel![event.altKey]"
)

interactionY = alt.selection_interval(bind='scales', encodings=['x'],on="[mousedown[event.shiftKey], mouseup] > mousemove",translate="[mousedown[event.shiftKey], mouseup] > mousemove!",
    zoom="wheel![event.shiftKey]")
ScatterLine=alt.Chart(df).mark_point(filled=True).encode(x=alt.X('@timestamp:T', title='TIMESTAMP'),y=alt.Y('value:Q', title='value'),  color=color,shape=shape_Operation,tooltip = ['value:N','NUMBER:N','SHAPE TYPE:N', alt.Tooltip('@timestamp:T', format = '%Y-%m-%d %H:%M'),'ID:N']
).add_selection(interaction1,interactionY,selection,selection1,selection_Operation).resolve_scale(  x='independent').transform_filter(selection & selection1)

ScatterLine 

saveVegaLiteVis(es, 'index-pattern1', 'RapresentationPoint', ScatterLine, timeField=True)

你怎么会看到下面有一个仅由saveVegaLiteVis例程生成的错误。我试图修改saveVega插入一个resultSize=1000000,但同时产生下面的错误。我该如何解决这个问题?我想确定问题只是出在保存这个以便将信息插入仪表板上。这意味着可视化本身可以工作。

---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
/usr/lib/python3/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    420                     # Otherwise it looks like a bug in the code.
--> 421                     six.raise_from(e, None)
    422         except (SocketTimeout, BaseSSLError, SocketError) as e:

/usr/lib/python3/dist-packages/six.py in raise_from(value, from_value)

/usr/lib/python3/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    415                 try:
--> 416                     httplib_response = conn.getresponse()
    417                 except BaseException as e:

/usr/lib/python3.8/http/client.py in getresponse(self)
   1346             try:
-> 1347                 response.begin()
   1348             except ConnectionError:

/usr/lib/python3.8/http/client.py in begin(self)
    306         while True:
--> 307             version, status, reason = self._read_status()
    308             if status != CONTINUE:

/usr/lib/python3.8/http/client.py in _read_status(self)
    267     def _read_status(self):
--> 268         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    269         if len(line) > _MAXLINE:

/usr/lib/python3.8/socket.py in readinto(self, b)
    668             try:
--> 669                 return self._sock.recv_into(b)
    670             except timeout:

timeout: timed out

During handling of the above exception, another exception occurred:

ReadTimeoutError                          Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/elasticsearch/connection/http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    250 
--> 251             response = self.pool.urlopen(
    252                 method, url, body, retries=Retry(False), headers=request_headers, **kw

/usr/lib/python3/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    718 
--> 719             retries = retries.increment(
    720                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

/usr/lib/python3/dist-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    375             # Disabled, indicate to re-raise the error.
--> 376             raise six.reraise(type(error), error, _stacktrace)
    377 

/usr/lib/python3/dist-packages/six.py in reraise(tp, value, tb)
    702                 raise value.with_traceback(tb)
--> 703             raise value
    704         finally:

/usr/lib/python3/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    664             # Make the request on the httplib connection object.
--> 665             httplib_response = self._make_request(
    666                 conn,

/usr/lib/python3/dist-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    422         except (SocketTimeout, BaseSSLError, SocketError) as e:
--> 423             self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
    424             raise

/usr/lib/python3/dist-packages/urllib3/connectionpool.py in _raise_timeout(self, err, url, timeout_value)
    329         if isinstance(err, SocketTimeout):
--> 330             raise ReadTimeoutError(
    331                 self, url, "Read timed out. (read timeout=%s)" % timeout_value

ReadTimeoutError: HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

ConnectionTimeout                         Traceback (most recent call last)
<ipython-input-31-45635f0d8635> in <module>
----> 1 saveVegaLiteVis(es, 'index-pattern', 'RapresentationPoint', ScatterLine, timeField=True,resultSize=100000)

<ipython-input-3-984bfed0a208> in saveVegaLiteVis(client, index, visName, altairChart, resultSize, timeField)
     46     }
     47 
---> 48     return client.index(index='.kibana',id='visualization:'+visName,body=visSavedObject)
     49 
     50 def saveVegaVis(client, index, visName, altairChart, resultSize=100, timeField=True):

~/.local/lib/python3.8/site-packages/elasticsearch/client/utils.py in _wrapped(*args, **kwargs)
    166                 if p in kwargs:
    167                     params[p] = kwargs.pop(p)
--> 168             return func(*args, params=params, headers=headers, **kwargs)
    169 
    170         return _wrapped

~/.local/lib/python3.8/site-packages/elasticsearch/client/__init__.py in index(self, index, body, doc_type, id, params, headers)
    404             doc_type = "_doc"
    405 
--> 406         return self.transport.perform_request(
    407             "POST" if id in SKIP_IN_PATH else "PUT",
    408             _make_path(index, doc_type, id),

~/.local/lib/python3.8/site-packages/elasticsearch/transport.py in perform_request(self, method, url, headers, params, body)
    413                         raise e
    414                 else:
--> 415                     raise e
    416 
    417             else:

~/.local/lib/python3.8/site-packages/elasticsearch/transport.py in perform_request(self, method, url, headers, params, body)
    379 
    380             try:
--> 381                 status, headers_response, data = connection.perform_request(
    382                     method,
    383                     url,

~/.local/lib/python3.8/site-packages/elasticsearch/connection/http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    261                 raise SSLError("N/A", str(e), e)
    262             if isinstance(e, ReadTimeoutError):
--> 263                 raise ConnectionTimeout("TIMEOUT", str(e), e)
    264             raise ConnectionError("N/A", str(e), e)
    265 

ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=10))

共有1个答案

沈德寿
2023-03-14

我设法解决了在es设置中增加一个更高的requestime的问题。

es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30)

(此信息由另一个问题链接获取

为了避免系统崩溃,我还需要增加 kibana 所需的磁盘空间。为此,我在 kibana.yml 的环境部分插入“--max-old.space-size=2048”

 类似资料:
  • 我是拉威尔的新手,需要帮助。当我点击

  • 我刚刚开始学习SpringMVC。我试图将一些数据从Thymeleaf表单保存到存储库,这扩展了CrudRepository。不幸的是,数据没有显示。 当我进入结果页面时,我看到使用的ID,但没有键入要形成的数据。哪里出了错? 这是控制器 `型号: 存储库: 表格摘录: 并从结果模板中提取:

  • 我正在Metabase上创建一个仪表板,以便将其嵌入到应用程序中。这个仪表板有两个问题,其中一个是使用元数据库查询生成器(AOV)创建的,另一个是使用SQL(GMV)创建的。当我在问题上设置brand_id参数时,我得到一个错误,说明在运行查询时发生了错误,但是AOV问题的一切工作都很好。你能帮帮我吗? 我得到的错误是: 缺少ID:{…}Values:Object{Values:(60)[…],H

  • 仪表板可用于集中管理和分享可视化控件集合。构建一个仪表板用以包含您在本教程中已保存的可视化控件,方法如下: 在侧边导航栏点击 Dashboard 。 点击 Add 显示已保存的可视化控件列表。 单击 Markdown Example 、 Pie Example 、 Bar Example 和 Map Example ,然后通过点击列表底部向上的小箭头关闭可视化控件列表。 将鼠标悬停在一个可视化控件

  • 在运行将StringBuilder的内容保存到.xlsx文件的代码时,它给出了以下错误: 线程“main”java.lang.nosuchmethoderror:org.apache.poi.util.poilogger.log(iljava/lang/object;ljava/lang/throwable;)V在org.apache.poi.openxml4j.opc.zippackage.bu

  • 我正在尝试从.csv构建报告仪表板,该.csv由我在Jmeter上运行的性能测试脚本生成,但它不起作用。检查JMeter.log文件,我注意到模板文件无法处理,但我不明白为什么。 这里有人面对过这个问题吗?有人知道怎么解决吗? 请参阅下面的日志行: 提前谢谢!