我正在尝试使用Item
gem将tire
模型的映射转换为与elasticsearch-rails
gem等效的映射:
tire do
mapping(
_parent: { type: 'player' },
_routing: { required: true, path: :user }
) do
indexes :user, type: "string", index: :not_analyzed
end
我在
elasticsearch-rails
中的映射是:mapping(_parent: {type: 'player', require: 'true', _routing: {path: 'user', required: 'true'}}) do
indexes :user, type: "string", index: not_analyzed
end
在尝试导入一些播放器之前,这似乎还行:
transform_function = lambda do |item|
{
index: {
_id: item.id,
_parent: item.player_id,
_routing: item.user_id,
data: item.__elasticsearch__.as_indexed_json
}
}
Item.__elasticsearch__.import \
index: 'my_index',
batch_size: 100,
transform: transform_function
尝试导入内容时出现错误:
Elasticsearch::Transport::Transport::Errors::BadRequest: [400]
{
"error" : "MapperParsingException[The provided routing value [1] doesn't match the routing key stored in the document: [null]]",
"status":400
}
我不知道该错误意味着什么,而且我似乎无法在网上找到适用的说明。其他遇到此错误的人似乎在做不同的事情...
我认为这只是我如何在
elasticsearch-rails
中声明映射的问题。不幸的是,关于它的外观并没有太多的文档...有人有想法吗? 最佳答案
我不知道是谁对此问题投了反对票,但我认为这是一个完全有用的问题。
原来,当您不需要path
时。您实际上可以像这样设置路由部分:
_routing: {type: 'user', required: 'true'})
我希望这可以帮助别人。
对于对此问题持否定态度的人:也许不是在无缘无故地使这个社区不受欢迎的地方,而是添加评论以解释为什么这个问题不好。
关于ruby-on-rails - 如何在带有Elasticsearch-rails的映射中设置路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33529253/