ElasticSearch学习笔记-Python API使用
1. 参考资料
- Elasticsearch 开发指南
- Elasticsearch 官网
- CSDN文章
- ElasticSearch博客园
- Python操作ElasticSearch
- ElasticSearch Python API官网
2. 代码实例
通过Python简单操作ElasticSearch
# -.- coding:utf-8 -.-
import json
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
class ElasticObj:
def __init__(self, index_name, index_type, index_conf, ip="127.0.0.1"):
"""
ElasticObj initialize
:param index_name: 索引名称
:param index_type: 索引类型
"""
self.index_name = index_name
self.index_type = index_type
self.index_conf = index_conf
# 无用户名密码状态
self.es = Elasticsearch(hosts=[ip])
# 用户名密码状态
# self.es = Elasticsearch([ip], http_auth=('elastic', 'password'), port=9200)
def create_index(self):
"""
Create an i