Searchkick::InvalidQueryError(映射错误 - 运行 Record.reindex)

Searchkick::InvalidQueryError (Bad mapping - run Record.reindex)

为 Rails 6 应用从 Elasticsearch 迁移到 Opensearch(1.3.1,Mac 自制软件)引起的另一个问题。

Loading test environment (Rails 6.1.4.7)
>> r = Record.find(638205575)
  Record Load (0.4ms)  SELECT "records".* FROM "records" WHERE "records"."id" =  LIMIT   [["id", 638205575], ["LIMIT", 1]]
=> #<Record id: 638205575, created_at: "2022-04-22 08:47:01.931397000 +0000", updated_at: "2022-04-22 08:47:01.931397000 +0000", metadata: {...
>> Record.search(r.name)
  Record Search (12.2ms)  records_test/_search {"query":{"bool":{"should":[{"dis_max":{"queries":[{"multi_match":{"query":"Eighth Record","boost":10,"operator":"and","analyzer":"searchkick_search","fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Eighth Record","boost":10,"operator":"and","analyzer":"searchkick_search2","fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Eighth Record","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true,"fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Eighth Record","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true,"fields":["*.analyzed"],"type":"best_fields"}}]}}]}},"timeout":"11s","_source":false,"size":10000}
Traceback (most recent call last):
Searchkick::InvalidQueryError (Bad mapping - run Record.reindex)

我在该输出中看不到任何指示查询无效或映射错误的信息。实际上 运行 Record.reindex 没有显示任何错误,只是在控制台中用 true 响应。

任何人都可以看到任何可能提供线索的东西吗?

这个问题的原因与 and, ultimately, to Searchkick memory leak有关。

用自定义 rake 任务代替 rake searchkick:reindex:all 导致无法正确构建索引。例如,这是两个不同结果的差异(右侧 searchkick 任务的正确索引):

"records_development" : {                       |   "records_development_20220425162622176" : {
    "aliases" : { },                                          |     "aliases" : {
                                                              >       "records_development" : { }
                                                              >     },
    "mappings" : {                                                  "mappings" : {
                                                              >       "dynamic_templates" : [
                                                              >         {
                                                              >           "string_template" : {
                                                              >             "match" : "*",
                                                              >             "match_mapping_type" : "string",
                                                              >             "mapping" : {
                                                              >               "fields" : {
                                                              >                 "analyzed" : {
                                                              >                   "analyzer" : "searchkick_index",
                                                              >                   "index" : true,
                                                              >                   "type" : "text"
                                                              >                 }
                                                              >               },
                                                              >               "ignore_above" : 30000,
                                                              >               "type" : "keyword"
                                                              >             }
                                                              >           }
                                                              >         }
                                                              >       ],
      "properties" : {                                                "properties" : {
        "abbreviation" : {                                              "abbreviation" : {
          "type" : "text",                                    |           "type" : "keyword",
                                                              >           "ignore_above" : 30000,
          "fields" : {                                                    "fields" : {
            "keyword" : {                                     |             "analyzed" : {
              "type" : "keyword",                             |               "type" : "text",
              "ignore_above" : 256                            |               "analyzer" : "searchkick_index"
                                                              >             },
                                                              >             "word_middle" : {
                                                              >               "type" : "text",