elasticsearch 写入数据并查询
#导入相关数据
import tushare as ts
import pandas as pd
#import elasticsearch as es
from datetime import datetime
from elasticsearch import Elasticsearch
df=ts.get_hist_data('000001')
#print(df)
df1=df.iloc[:10]
es = Elasticsearch()
for k in df1.index:
a=df1.loc[k]
b=dict(a)
res = es.index(index=str(k), doc_type='stock', id=1, body=b)
#res = es.get(index="2018-07-31", doc_type='stock', id=1)
res1 = es.search(index="2018-07-31", body={"query": {"match_all": {}}})
print( res1['hits']['hits'])
for hit in res1['hits']['hits']:
print( hit["_source"])