elasticsearch_cheetsheat

目录

目录

es的curd

curl操作es

python操作es

connect es

update_by_query

delete_by_query

问题排查汇总


es的curd

curl操作es


1、写入

POST _bulk
{"index":{"_index":"index_name-2021-09-15","_type":"doc","_id":"3"}}
{"phone" : "13810172311", "logtime" : "2021-09-15 00:00:01"}

2、update by query

Update By Query API | Elasticsearch Guide [7.14] | Elastic

POST my_index/_update_by_query?refresh
{
  "script":{
    "source":"ctx._source.flag='finish'", # 直接赋值,也可以"ctx._source.count++" 数值型计算
    "lang":"painless"
  },
  "query":{
    "term":{
      "_id":"-KapDHwBHyKyjyAVIqyG"
    }
  }
}

refresh的目的是update之后立即刷新文档。 

python操作es

connect es

http_auth=(es_user, es_password)
verify_certs=False  # 确认没有加密证书
retry_on_timeout=True 
max_retries=5
sniff_on_start=True,sniff_on_connection_fail=True,sniffer_timeout=600 # 增加嗅探机制

加入使用ssl
use_ssl=True #打开SSL
verify_certs=True#确保我们验证了SSL证书,默认是false
ca_cets="/path/to/CA_certs" # 提供CA证书的路径
client_cert='/path/to/clientcert.pem' # PEM格式的SSL客户端证书client_key='/path/to/clientkey.pem' # PEM格式的SSL客户端密钥

update_by_query

使用过程中遇到的问题:

version conflict,required seqNo [],primary term [],but no document was found

原因是存在了并发,version冲突,而实际上代码中没有并发场景,经排查是由于index所属的template中设置了refresh时间间隔为30s,导致update之后并没有及时更新document,所以在调用时加上参数refresh=True,即可避免这种问题。

 es_service.update_by_query(index=index_name, doc_type="", body=update_body, refresh=True)

delete_by_query

query = {'query': {'range': {'age': {'lt': 11}}}}

es.delete_by_query(index='indexName', body=query, doc_type='typeName')


 

问题排查汇总

1、spark写入es:

org.elasticsearch.hadoop.rest.EsHadoopRemoteException: 
cluster_block_exception: blocked by: [FORBIDDEN/8/index write (api)]

原因是index所属的生命周期中设置了warm阶段计时,到这个阶段index会被设置为只读。所以 forbidden write

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值