Количество записей не совпадает в кадрах данных кибаны и панд - PullRequest
0 голосов
/ 21 сентября 2018

Я получаю данные из упругого поиска в панды, используя метод поиска и сканирования.Количество моих документов исчисляется миллиардами и миллионами.Я заметил странную вещь.Когда я сопоставляю числа в моих пандах и кибане за один и тот же период времени, цифры не совпадают.Чем больше продолжительность, тем больше разница, которую я получаю.Иногда его больше в кибане, а иногда в пандах за тот же период времени, но в основном больше в пандах.Это нормально?или это происходит из-за объема данных, которые я анализирую?

Короче говоря, почему существует разница в количестве записей в кибане и пандах?

Ниже приведенокод, который я использую для получения данных из упругого поиска: -

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()))

1 Ответ

0 голосов
/ 21 сентября 2018

У меня возникла та же проблема, и я получил только один ответ: проблема сasticsearch в том, что он обновляет индекс только очень часто (по умолчанию каждую секунду), когда происходит обновление, поэтому число может быть не точным на 100%в любой момент.

Вы можете сослаться на ссылку ниже, где я разместил вопрос, но не смог получить большую помощь: -

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

...