Python 操作ES

pip安裝相關庫

from elasticsearch import Elasticsearch

#連接
es = Elasticsearch("192.168.19.14:9200")
#插入
body =  {"device": {"type": "Router","vendor": "TP-Link"},"ip": "194.223.52.142"}
es.index(index="index",doc_type="doc_type",body=body)
#查詢
query = {'query': {'term': {'ip': '194.223.52.142'}}}
es.search(index='iot_test',doc_type='iot_asset',body=query)
#刪除
es.delete_by_query(index="iot_history",doc_type="iot_asset", body=query)

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章