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)

原文地址:https://www.cnblogs.com/loveyouyou616/p/11573044.html