Elasticsearch-什么更快?为相同的文档编制索引或使用detect_noop更新:是吗?

安东

我有一个父子文档映射,而父文档只有一个contact_id字段。而且,当我插入新的子文档时,我需要确保该父文档存在。它可能已经存在或可能不存在。

因此,我使用Bulk API插入父级(如果不存在),然后在一个请求中插入一个子级。

我的问题是哪种方法更快:update使用doc_as_upsertdetect_noop或将index新记录与可能已经存在的相同数据进行比较:

{ update: { _index: 'index_name', _type: 'contact', _id: 25, _routing: 14}}
{ doc: { contact_id: 25 }, doc_as_upsert: true, detect_noop: true }
{ index: { _index: 'index_name', _type: 'event', _routing: 14, _parent: 25}}
{ ... event document body ...}

或者

{ index: { _index: 'index_name', _type: 'contact', _id: 25, _routing: 14}}
{ contact_id: 25 }
{ index: { _index: 'index_name', _type: 'event', _routing: 14, _parent: 25}}
{ ... event document body ...}
安东

看起来它执行相同的操作:

                   user     system      total        real
update_10k_x1  6.460000   1.720000   8.180000 ( 79.737009)
index_10k_x1   6.300000   1.680000   7.980000 ( 80.067855)
update_10k_x2  12.660000   3.350000  16.010000 (159.787347)
index_10k_x2   12.690000   3.380000  16.070000 (160.276717)
update_10k_x3  18.870000   5.000000  23.870000 (242.023184)
index_10k_x3   18.940000   5.030000  23.970000 (240.063431)

这是基准代码:

require 'benchmark'
require 'elasticsearch-ruby'

$client = Elasticsearch::Client.new

def update_10k(n)
  index_name = "#{__method__}_x#{n}"
  n.times do
    (1..10000).each do |id|
      body = []
      body << { update: {_index: index_name, _type: :contact, _id: id }}
      body << { doc: { contact_id: id }, doc_as_upsert: true, detect_noop: true }
      $client.bulk body: body
    end
  end
end

def index_10k(n)
  index_name = "#{__method__}_x#{n}"
  n.times do
    (1..10000).each do |id|
      body = []
      body << { index: {_index: index_name, _type: :contact, _id: id }}
      body << { contact_id: id }
      $client.bulk body: body
    end
  end
end

Benchmark.bm do |x|
  (1..3).each do |n|
    x.report("update_10k_x#{n}") { update_10k(n) }
    x.report("index_10k_x#{n}") { index_10k(n) }
  end
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

索引编制期间Elasticsearch MapperParsingException [无法解析,文档为空]

来自分类Dev

索引编制期间Elasticsearch MapperParsingException [无法解析,文档为空]

来自分类Dev

Elasticsearch中的索引编制

来自分类Dev

ElasticSearch-使用Java API为大型文件编制索引

来自分类Dev

ElasticSearch-使用Java API为大型文件编制索引

来自分类Dev

Elasticsearch-什么是索引编制过程?

来自分类Dev

在Elasticsearch中克隆索引和为其重新编制索引有什么区别?

来自分类Dev

并非所有文档都使用ElasticSearch和MongoDB编制了索引

来自分类Dev

Elasticsearch更新索引模板

来自分类Dev

如何使用NEST更新ElasticSearch索引内的现有文档?

来自分类Dev

如何使用NEST更新ElasticSearch索引内的现有文档?

来自分类Dev

使用Python UTF-8问题进行Elasticsearch索引编制

来自分类Dev

如何使用Elasticsearch对视图内容编制索引?

来自分类Dev

Python Elasticsearch 7.05索引编制失败

来自分类Dev

使用ElasticSearch索引mongoDB

来自分类Dev

路由Elasticsearch文档索引问题

来自分类Dev

Elasticsearch 使用匹配的 id 更新文档

来自分类Dev

Elasticsearch:处理经常更新的文档

来自分类Dev

Elasticsearch Jest更新整个文档

来自分类Dev

在Elasticsearch中更新文档

来自分类Dev

在Elasticsearch中更新过滤的文档

来自分类Dev

在elasticsearch中更新多个文档?

来自分类Dev

Elasticsearch有复合索引吗?

来自分类Dev

如何使用NEST为Elasticsearch指定索引?

来自分类Dev

Elasticsearch 以实体为中心的索引

来自分类Dev

如何从Elasticsearch删除文档

来自分类Dev

ElasticSearch文档脚本排序

来自分类Dev

ElasticSearch中的随机文档

来自分类Dev

恢复Elasticsearch文档

Related 相关文章

热门标签

归档