Я получаю данные от эластичного поиска до панд, используя метод поиска и сканирования. Количество моих документов - миллиарды и миллионы. Я заметил странную вещь. Когда я сопоставляю числа в своих пандах и кибанах за тот же период времени, цифры не совпадают. Чем больше продолжительность, тем больше разница, которую я получаю. Иногда его больше в кибане, а иногда и в пандах за тот же период времени, но в основном ее больше в пандах. Это нормально? или это происходит из-за объема данных, которые я обрабатываю?
Короче говоря, почему существует разница в количестве записей в кибане и пандах?
Ниже приведен код, который я использую для получения данных из эластичного поиска: -
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()))
У меня такая же проблема, и я получил один ответ. Проблема с elasticsearch заключается в том, что обновление индекса происходит только каждый раз (по умолчанию каждую секунду), когда происходит обновление, поэтому число может быть не точным на 100% в любой момент,
Вы можете ссылаться на приведенную ниже ссылку, где я опубликовал эту проблему, но не смог получить большую помощь:
https://github.com/elastic/elasticsearch-dsl-py/issues/1019#issuecomment-423372421