我正在编写一些代码来查询Elasticsearch中的数据。我们有大量的数据,所以我正在使用扫描功能并搜索特定的索引。我们按天为Elasticsearch编制索引,例如today = index_2019_04_15
和yesterday = index_2019_04_14
。有什么方法可以只查询前几天的索引?
第二,在完成_all然后将查询限制为2019-04-14
方面,我会看到性能受到很大的影响吗?如果没有,那么我可以进行前一天的查询。
这是我的代码:
import pandas as pd
from elasticsearch_dsl import Search
from elasticsearch_dsl import connections
class get_data:
def __init__(self, host, query):
self.host = host
self.query = query
def pull_es_data(self):
connections.create_connection(alias='client',hosts=self.host,timeout=60)
s = Search(using='client', index="data-2019-04-15") \
.query("match", clientid=r"AB1234-12345")
response = s.scan()
return response
test = get_data("localhost","test")
x = test.pull_es_data()
results_df = pd.DataFrame(([item.clientid,item.clientlocation] for item in x),\
columns=['clientid','clientlocation'])
答案 0 :(得分:0)
我能够使用Elasticsearch-dsl中的Index来解决此问题
def get_index_list(self):
i = Index("*").get_alias("client")
return i