所以我一直试图让这项工作几个小时,似乎没有任何工作。
我有 mappings
在我的模型中定义:
settings do
mappings dynamic: false do
indexes :title, type: 'text'
indexes :description, type: 'text'
indexes :user, type: 'text' do
indexes :name, type: 'text'
end
end
end
但是当我这样做时:
Podcast.__elasticsearch__.delete_index! force: true
Podcast.__elasticsearch__.create_index! force: true
Podcast.__elasticsearch__.import force: true
并访问:
http://localhost:9200/podcasts/_search?pretty=true&q=*:*&size=1000
我看到所有模型数据都倒入索引中(我只需要标题、描述和用户名)。
这里有什么问题?
最佳答案
索引时,rails-ealsticsearch 使用 as_indexed_json
.这是我的例子:
def as_indexed_json(options = {})
as_json(include: {
user: {
only: [
:id,
:slug,
:name
]
}
})
end
关于ruby-on-rails - Rails elasticsearch 映射被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50027359/