[elasticsearch笔记] refresh/optimistic_concurrency_control

本文深入探讨了Elasticsearch中数据写入后的搜索延迟问题,解析了refresh机制的作用及配置选项,如emptystring、true、false、wait_for等,并介绍了乐观并发控制策略,包括_seq_no、_primary_term和_version字段的使用,以确保数据一致性。

重点

  • 数据写入后,并不是马上可以search到,需要refresh(index.refresh_interval 默认1s
  • refresh
    • empty string or true
    • wait_for
    • false (the default)
  • optimistic concurrency control
    • sequence number_seq_no) 通过该字段确保 旧数据 不会覆盖 新数据
    • _seq_no: index全局自增
    • _primary_term: 指定存储主分片
    • _version: 该索引的版本号,默认每次修改都会自增

refresh

  GET /twitter/_search
  {
    "query": {
      "match_all": {}
    }
  }
  
  PUT /twitter/_doc/1?refresh
  {
    "fullname": "zhengcj01",
    "text":"hello"
  }
  
  PUT /twitter/_doc/2?refresh=true
  {
    "fullname": "dongyc",
    "text":"how do you do"
  }
  
  PUT /twitter/_doc/3
  {
    "fullname": "liuhh",
    "text":"hello"
  }
  PUT /twitter/_doc/4?refresh=false
  {
    "fullname": "zhengzj",
    "text":"how do you do"
  }
  
  PUT /twitter/_doc/5?refresh=wait_for
  {
    "fullname": "zhengwj",
    "text":"how do you do"
  }

optimistic concurrency control

PUT products/_doc/1567?if_seq_no=362&if_primary_term=2
{
    "product" : "r2d2",
    "details" : "A resourceful astromech droid",
    "tags": ["droid"]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值