es python demo
生活随笔
收集整理的這篇文章主要介紹了
es python demo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
from elasticsearch import Elasticsearch# 默認host為localhost,port為9200.但也可以指定host與port
es = Elasticsearch()# 添加或更新數據,index,doc_type名稱可以自定義,id可以根據需求賦值,body為內容
es.index(index="my_index",doc_type="test_type",id=1,body={"name":"python","addr":"深圳"})# 或者:ignore=409忽略文檔已存在異常
es.create(index="my_index",doc_type="test_type",id=1,ignore=409,body={"name":"python","addr":"深圳"})from elasticsearch import Elasticsearches = Elasticsearch()# 獲取索引為my_index,文檔類型為test_type的所有數據,result為一個字典類型
result = es.search(index="my_index",doc_type="test_type")# 或者這樣寫:搜索id=1的文檔
result = es.get(index="my_index",doc_type="test_type",id=1)print(result)# 打印所有數據
總結
以上是生活随笔為你收集整理的es python demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu 配置git
- 下一篇: Python Elasticsearc