python 使用 elasticsearch 经常使用方法(索引)

#记录管理索引等方法

from elasticsearch import Elasticsearch

es = Elasticsearch(['xx.xx.xx.xx:9200'])

#获取文档内容
res = es.get_source(index="test", id='-R7AQ20BIdlTveXFPOTI')
print(res)

#获取文档信息
res = es.get(index="test", id='-R7AQ20BIdlTveXFPOTI')
print(res['_source'])

#更新文档
res = es.update(index="test", id='-R7AQ20BIdlTveXFPOTI', body={"doc": {"age": 37, "country": "china"}})
print(res)

#索引是否存在
print(es.indices.exists(index="test"))

#删除文档
print(es.delete(index="test", id="-h7AQ20BIdlTveXFeOSg"))

#多条数据查询
res = es.mget(index="test", body={'ids': ["1", "-R7AQ20BIdlTveXFPOTI"]})
print(res)


#index建立索引res = es.index(index="school", body = { 'mappings': { '_source': { 'enabled': True }, 'properties': { 'content': {'type': 'keyword'} } }})print(res)
相关文章
相关标签/搜索