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)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM