亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于python操作ES實(shí)例詳解

 更新時(shí)間:2019年11月16日 15:19:52   作者:太虛真人  
這篇文章主要介紹了基于python操作ES實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了基于python操作ES實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

安裝

pip install elasticsearch5 # 安裝對應(yīng)版本的模塊

創(chuàng)建ES對象

from elasticsearch5 import Elasticsearch 

# elasticsearch集群服務(wù)器的地址
ES = [
  '127.0.0.1:9200'
]

# 創(chuàng)建elasticsearch客戶端
es = Elasticsearch(
  ES,
  # 啟動前嗅探es集群服務(wù)器
  sniff_on_start=True,
  # es集群服務(wù)器結(jié)點(diǎn)連接異常時(shí)是否刷新es節(jié)點(diǎn)信息
  sniff_on_connection_fail=True,
  # 每60秒刷新節(jié)點(diǎn)信息
  sniffer_timeout=60
)

搜索數(shù)據(jù)

query = {
  'query': {
    'bool': {
      'must': [
        {'match': {'_all': 'python web'}}
      ],
      'filter': [
        {'term': {'status': 2}}
      ]
    }
  }
}
ret = es.search(index='articles', doc_type='article', body=query)

添加數(shù)據(jù)

doc = {
     'article_id': article.id,
     'user_id': article.user_id,
     'title': article.title
   }
es.index(index='articles', doc_type='article', body=doc, id=article.id)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論