耐嚼的宝石将Elasticsearch日期类型反序列化为字符串

时间:2018-08-31 18:43:21

标签: ruby-on-rails chewy-gem

使用Chewy从ES检索结果时,日期键入的结果将作为Ruby字符串返回。

我的索引定义如下:

class OrdersIndex < Chewy::Index
  define_type Order do

    field :id, type: "keyword"
    field :created_at, type: "date"
  end
end

检索结果时:

OrdersIndex.order(created_at: :desc).first.created_at.class
# => String

是否有一种方法可以自动在Ruby日期对象中反序列化此日期字段,而不必使用Time#parse显式映射结果?

0 个答案:

没有答案
相关问题