python elasticsearch
生活随笔
收集整理的這篇文章主要介紹了
python elasticsearch
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文鏈接
文檔:http://elasticsearch-py.readthedocs.io/en/master/
Elasticsearch官方API文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html
兩種方式現實Elasticsearch API操作
方式一:安裝elasticsearch模塊,通過它操作Elasticsearch,代碼示例如下
方式二:安裝requests模塊,通過GET、POST方式操作Elasticsearch
class RequestsElasticSearchClass(object):def __init__(self, host, port, user, passwrod):self.url = 'http://' + host + ':' + str(port)basicpwd = base64.b64encode((user + ':' + passwrod).encode('UTF-8'))self.headers = {"User-Agent": "shhnwangjian","Content-Type": "application/json","Authorization": "Basic {}".format(basicpwd.decode('utf-8'))}def search(self, indexname, size=10):gettdata = {"sort": "@timestamp:desc","size": size}url = self.url + '/' + indexname + '/_search'ret = requests.get(url, headers=self.headers, timeout=10, params=gettdata)print(ret.text)總結
以上是生活随笔為你收集整理的python elasticsearch的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: elasticsearch 写入数据并查
- 下一篇: elasticsearch pytho