1

模型:

class Item
    store :socket_store, accessors: [:sockets, :socket_count, :socket_link_count]
end

映射:

mapping do
  indexes :id,                    key: "value", index: :not_analyzed
  indexes :sockets,               type: "object"
  indexes :socket_count,          type: "integer"
  indexes :socket_link_count,     type: "integer"
end

但这是我的实际索引的样子:

socket_cout并且其他 2 个属性不在映射的根部,就好像它们被完全忽略了一样。

我知道我可以创建具有不同名称的方法并将它们添加到 to_indexed_json,但我猜它应该按原样工作。

4

1 回答 1

1

好,我知道了。

由于键值存储的访问器不是Item模型上的实际属性,因此需要将它们作为方法添加到方法中to_indexed_json

def to_indexed_json
    to_json(include: [:stats], exclude: [:sockets_store], methods: [:socket_count, :socket_link_count, :sockets])
end

就是这样!

于 2013-03-05T19:59:41.927 回答