单个记录的重复搜索索引

时间:2021-01-15 13:55:08

标签: ruby-on-rails elasticsearch searchkick

我有一个模型用户,我正在通过 Searchkick 在 ElasticSearch 中对其进行索引:

class User < ActiveRecord::Base
  searchkick callbacks: :async, routing: true
end

我还有一个后台工作来有条件地重新索引。 问题是在某些情况下,我为单个用户重复了索引:

2.3.8 :191 > u = User.find_by_email("john.doe@mail.com") 
=> #<User id: 401953, email: "john.doe@mail.com", name: "John Doe", university_id: 83, device_id: "b3f3d62839ca6b981ea236562e6da9ff", app_version: "6.7.0>

但我有相同的 id 和 _index 的重复 searchkick 索引!

2.3.8 :192 > ap User.search("*", where: {email: "john.doe@mail.com"}, load: false).results
 [
    [0] {
                "_index" => "users_production_20200717081323100",
                 "_type" => "user",
                   "_id" => "401953",
                "_score" => 1.0,
              "_routing" => "123",
              "email" => "john.doe@mail.com",
         app_version" => "6.6.0",
                 "id" => "401953"
    },
    [1] {
                "_index" => "users_production_20200717081323100",
                 "_type" => "user",
                   "_id" => "401953",
                "_score" => 1.0,
              "_routing" => "123",
              "email" => "john.doe@mail.com",
         app_version" => "6.7.0",
                 "id" => "401953"
    }
]

唯一改变的属性是 app_version。在某些时候,用户拥有“6.6.0”版本,当更新到 6.7.0 时,索引会重复。在这种情况下,为什么会发生这种情况?这是宝石的正常行为吗?。不应该更新并留下一个索引吗?

问候

0 个答案:

没有答案
相关问题