【问题标题】:How to update Elasticsearch field type with Chewy如何使用 Chewy 更新 Elasticsearch 字段类型
【发布时间】:2018-10-26 00:40:57
【问题描述】:

我的问题是关于使用 elasticsearch ruby​​ 客户端 chewy 更改弹性搜索索引中的字段类型。

我正在尝试更新索引中的字段类型。我收到此错误:illegal_argument_exception

我读到不可能更改现有索引中的类型,所以我正在考虑重新索引所有内容:rake chewy:reset。我已经尝试了很多事情......我无法让我的重新索引工作。

详细错误:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [enabled] cannot be changed from type [text] to [boolean]"}],"type":"illegal_argument_exception","reason":"mapper [enabled] cannot be changed from type [text] to [boolean]"},"status":400}

我以前的索引(默认情况下启用的字段是文本):

class SearchIndex < Chewy::Index
  define_type Company, delete_if: :deleted_at do
    ...
    field :enabled
    ...
  end
end

我想要的索引:

class SearchIndex < Chewy::Index
  define_type Company, delete_if: :deleted_at do
    ...
    field :enabled, type: 'boolean'
    ...
  end
end

如何使用 Chewy(如果可能,无需通过 curl 请求 ElasticSearch)来使用新字段类型重新索引我的索引?

谢谢。

【问题讨论】:

    标签: ruby elasticsearch chewy-gem


    【解决方案1】:

    我以前没有使用过 Chewy,但是查看文档,您应该可以在 ruby​​ 控制台中调用 SearchIndex.reset!。当然删除和重新创建索引是可能的,并且应该使用您的新数据类型从头开始重新创建。

    【讨论】:

    • 感谢您回答我的问题。我也尝试过,但它不起作用,我得到同样的错误......Elasticsearch不会让我在我的情况下重新索引/重置是否正常?没有 Chewy 怎么办?
    • SearchIndex.purge! 怎么样?那应该只是重新创建索引而不重新导入,这可能是它目前失败的地方。如果没有 Chewy,您将需要使用 Curl 与 ES 索引进行交互,根据 elastic.co/guide/en/elasticsearch/reference/current/…
    【解决方案2】:

    我发现为什么 Elsaticsearch 不希望我改变我的类型。这是因为我的索引有一些其他类型包含相同的字段(至少相同的字段名称),但具有另一种字段类型。

    因此,所有具有相同名称的字段必须具有相同的类型。然后您将能够(并且您必须)删除您的索引并重新创建它。 (SearchIndex::purge! 完成这项工作)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多