【Python】Elasticsearch和elasticsearch_dsl


官網:https://elasticsearch-py.readthedocs.io/en/master/api.html

官網:https://github.com/elastic/elasticsearch-py/tree/master/elasticsearch/client

官網:https://elasticsearch-dsl.readthedocs.io/en/latest/api.html

 

from elasticsearch_dsl import connections, Search
from elasticsearch import Elasticsearch
from elasticsearch.exceptions import *

es_object   = Elasticsearch(['url:9200'], sniffer_timeout=60, timeout=30)
# 獲取es中所有的索引
# 返回類型為字典,只返回索引名
es_object.cat.indices(format='json',h='index')
# 查詢多個索引
es_s_object = Search(using = es_object, index = ['log-2018-07-31','log-2018-07-30','log-2018-07-29'])
# 查詢一個索引
es_s_object = Search(using = es_object, index = 'log-2018-07-31')
# 條件查詢1
es_r_object = es_s_object.filter("range", timestamp={"gte": 1532879975, "lt":1532880095})
# 條件查詢2
es_r_object = es_r_object.filter("term", title = '12345')
# 結果轉換為字典
es_r_dict = es_r_object.execute().to_dict()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM