python如何连接es

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']

猜你喜欢

转载自blog.csdn.net/qq_35958094/article/details/82225676