python如何連線es
阿新 • • 發佈:2018-11-02
def connect_es(self): #連線es時host只寫ip es_host = 'http://192.168.97.38' es = Elasticsearch(hosts=es_host,port=9200,timeout=15000) body = {"query":{"bool": { "must": [{"term":{"exercisesId":"5d63f4930ae445c39d3461f3ed45a977"}}], "must_not":[], "should":[] }}, "from":0, "size":10, "sort":[], "aggs":{}} res = es.search(index="searchindex2", body=body) #獲取返回資料總量 ques_count = res['hits']['total'] #獲取返回資料 data = res['hits']['hits']