gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:47:00 25 4
gpt4 key购买 nike

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

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

我的问题是哪种方法更快:带有updatedoc_as_upsertdetect_noopindex带有可能已经存在的相同数据的新记录:

{ 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

关于elasticsearch - Elasticsearch-什么更快?为相同的文档编制索引或使用detect_noop更新:是吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30041764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com