(二)ElasticSearch6.1.1 Python API
生活随笔
收集整理的這篇文章主要介紹了
(二)ElasticSearch6.1.1 Python API
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
0、準備開啟數據庫
① 關閉Linux防火墻,這個很重要,否則API總是報錯連不上。
# 查看防火墻狀態 firewall-cmd --state# 關閉防護墻 systemctl stop firewalld.service# 開啟防火墻 systemctl start firewalld.service# 重啟防火墻 systemctl restart firewalld.service# 禁止firewalld開機啟動 systemctl disable firewalld.service② 啟動elasticsearch
bin/elasticsearch③ 啟動Kibana
bin/kibana1、使用conda或者pip安裝elasticsearch 6.1.1
# 使用conda conda install elasticsearch=6.1.1#使用pip pip install elasticsearch==6.1.12、主要的Python代碼
# -*- coding: utf-8 -*- from elasticsearch import Elasticsearchif __name__ == '__main__':es = Elasticsearch(['192.168.1.211'], http_auth=('elastic', '5tgbhu8'), port=9200)index = "my_index"dtype = "my_type"mappings = \{dtype: {"include_in_all": False,"properties": {"A": {"type": "nested","properties": {"A1": {"type": "keyword"},"A2": {"type": "long"}}},"B": {"type": "nested","properties": {"B1": {"type": "keyword"},"B2": {"type": "long"}}}}}}body = {"ThemeCount": [{"A1": "file","A2": 35},{"A1": "root","A2": 45}],"B": [{"B1": "work","B2": 56},{"B1": "etc","B2": 88}]}if es.indices.exists(index=index):es.indices.delete(index=index)es.indices.create(index=index)# 設置mappinges.indices.put_mapping(doc_type=dtype, body=mappings, index=index)es.index(index=index, doc_type=dtype, body=body)3、使用Kibana查看結果
# 在瀏覽器中打開 http://192.168.1.211:5601# Dev tools GET /my_index/_search 數據入到es庫中?
?
?
總結
以上是生活随笔為你收集整理的(二)ElasticSearch6.1.1 Python API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pytorch之trainer.zero
- 下一篇: robotframework调用pyth