【问题标题】:Count of records is not same in kibana and pandas dataframekibana 和 pandas 数据框中的记录数不同
【发布时间】:2018-09-21 12:29:05
【问题描述】:

我正在使用搜索和扫描方法从弹性搜索获取数据到熊猫。我的文件数以亿计。我注意到一件奇怪的事情。当我在同一时间段内匹配我的 pandas 和 kibana 中的数字时,数字是不一样的。持续时间越长,我得到的差异就越大。有时它更多地出现在 kibana 中,有时在同一时期出现在 pandas 中,但大多数情况下它在 pandas 中更大。这是正常的吗?还是因为我正在解析的数据量大?

长话短说,为什么 kibana 和 pandas 的记录数有差异?

下面是我用来从弹性搜索中获取数据的代码:-

import pandas as pd
import datetime
import elasticsearch
import elasticsearch.helpers
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from pandasticsearch import DataFrame
from pandasticsearch import Select
from elasticsearch import Elasticsearch, helpers
import os


# Define the client which will be our elastic cluster URL
client = Elasticsearch(['localhost.com:9200'])

# Define search method on the client by using the Search function.
search = Search(using=client)  # make sure that the Search function start with Capital S (Search(using=client)) as this is a function.

# Get all the results from the search method and store it in result to know how many hits we are getting.
results = search.execute()

# To know about the total number of hits we are getting run the below chunk.
results.hits.total  # (I got 3.9 billion hits as a result)


# Again I am defining a method s on which we will perform the query. you have to run this method everytime before running the query.
s = Search(using=client)

# add any filters/queries....

# The below line you can use if you want to dump all the data and in this case we have 2.3 billion observation.
#s = s.query({"match_all": {}})

# In the below code you can add filters,queries or time constraints.
s = s.query({"constant_score" : {
            "filter" : {
                 "bool" : {
                    "must" : [{
              "range": {"@timestamp" : {
                "gte": "2018-09-20T16:00:00.000Z", # gte - greater than
                "lte": "2018-09-20T17:00:00.000Z"  # lte - less than

            }}
          }],
                   "filter": [
                        {"term"  :{"type" :"abc"}}, 
                        {"term"  :{"ua" :"xyz"}},  
                        {"term"  :{"domain":"ghj"}},]        

                 }}}})

# After getting all the result in the variable s, we are applying scan method on it and converting it into a data frame.
results_df = pd.DataFrame((d.to_dict() for d in s.scan()))

【问题讨论】:

  • 您没有在搜索中定义任何特定索引?
  • 我的索引是每天的日期,所以它的工作方式就是这样。你有没有遇到过这样的问题。永远
  • 可能存在时区问题,因为 Kibana 在浏览器时区中显示日期。您是否使用 Inspector/Spy 面板检查了发送到 ES 的查询?
  • 我检查了时区...它们是相同的...差异不是很大,只有 1%,但我很好奇为什么我在熊猫中获得更多数字。我不确定检查员/间谍面板是什么。但我的问题是关于 kibana。我没有在 kibana 仪表板上得到准确的数字。我说得通吗?

标签: python elasticsearch logstash kibana elastic-stack


【解决方案1】:

我遇到了同样的问题,我只得到了一个答案,elasticsearch 的问题在于,当刷新发生时,它只会每隔一段时间(默认情况下是每秒)更新一次索引,所以这个数字可能不是 100% 准确的任何给定的时刻。

您可以参考以下链接,我已在其中发布了该问题但无法获得太多帮助:-

https://github.com/elastic/elasticsearch-dsl-py/issues/1019#issuecomment-423372421

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2019-06-18
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    相关资源
    最近更新 更多