【问题标题】:update elasticcache record without totally replacing it更新 elasticache 记录而不完全替换它
【发布时间】:2017-07-06 08:29:36
【问题描述】:

我正在使用它向 elasticcache 索引添加一堆记录:

  def self.index_trends(trend_hashes)
    formatted_trends = trend_hashes.map do |trend_hash|
      {
        index: {
          _index: 'trends',
          _type: 'trend',
          _id: trend_hash["id"],
          data: trend_hash
        }
      }
    end
    elasticsearch.bulk({
      body: formatted_trends
    })
  end

现在我需要更新一条记录(给定它的 id)。我只想向data 哈希添加一个键值,而不是替换整个状态。如何使用elasticsearch-ruby 做到这一点?

【问题讨论】:

    标签: ruby elasticsearch elasticsearch-ruby


    【解决方案1】:

    我不知道如何用 ruby​​ 做到这一点,但在 ES 中有update API

    看起来像这样

    POST test/type1/1/_update
    {
        "script" : "ctx._source.new_field = \"value_of_new_field\""
    }
    

    From example 与 ruby​​ 应该是

     client.update index: 'myindex', type: 'mytype', id: '1',
         body: { script: 'ctx._source.tags += tag', params: { tag: 'x' } }
    

    【讨论】:

    • 谢谢你会试一试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    相关资源
    最近更新 更多