- 前言:node
练习 elasticsearch_dsl 模块的增删改查与链接, 每条Python语句会转换成相应的 curl app
- 目录:curl
- Elasticsearch 链接elasticsearch
- 三种声明节点的方式ide
""" 三种声明节点的方式 """ es1 = Elasticsearch([ {'host': 'localhost'}, {'host': 'othernode', 'port': 443, 'url_prefix': 'es', 'use_ssl': True}, ]) es2 = Elasticsearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, # make sure we verify SSL certificates (off by default) verify_certs=True, # provide a path to CA certs on disk ca_certs='/path/to/CA_certs' ) es3 = Elasticsearch( [ 'http://user:secret@localhost:9200/', 'https://user:secret@other_host:443/production' ], verify_certs=True )
- 经常使用的方式:测试
es1 = Elasticsearch([ {'host': 'localhost'}, ])
- Elasticsearch 类中参数详解url
use_ssl = True # 使用 ssl 链接 verify_certs=True # 校验ssl证书, 默认为False ca_certs='/path/to/CA_certs' # CA证书的路径 client_cert='/path/to/clientcert.pem' # PEM格式的SSL客户端证书的路径 client_key='/path/to/clientkey.pem' # PEM格式ssl客户端秘钥的路径 connection_class=ThriftConnection # 指定本地链接使用的方式, 默认为 Transport sniff_on_start=True # 开启集群探测 sniff_on_connection_fail=True # 节点出错后进行刷新 sniffer_timeout=60 # 每60秒探测
- 增spa
- 索引:code
- 普通建立索引:blog
# 建立索引 es.indices.create(index="demo1") # 生成数据时无索引则建立索引 body = { "test": "测试数据" } ret = es.index(index="demo2", doc_type="demo2", body=body) # index() 会自动生成mapping mapping = { "demo2": { "mappings": { "demo2": { "properties": { "test": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } }
# curl:
# curl -X PUT http://localhost:9200/demo3
- 建立mapping, 根据mapping定义的doc自动建立索引:
- 建立 template:
- 新增数据
- 删
- 改
- 查