[英]How to set up routing in mapping with elasticsearch-rails
I'm trying to translate this mapping for an Item
model using the tire
gem to its equivalent with the elasticsearch-rails
gem: 我正在尝试将使用tire
gem的Item
模型的映射转换为与elasticsearch-rails
gem等效的映射:
tire do
mapping(
_parent: { type: 'player' },
_routing: { required: true, path: :user }
) do
indexes :user, type: "string", index: :not_analyzed
end
My mapping in elasticsearch-rails
is: 我在elasticsearch-rails
映射是:
mapping(_parent: {type: 'player', require: 'true', _routing: {path: 'user', required: 'true'}}) do
indexes :user, type: "string", index: not_analyzed
end
This seems okay until I try to import some players: 在尝试导入一些播放器之前,这似乎还可以:
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
I get an error when I try to import stuff: 尝试导入内容时出现错误:
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
}
I don't know what that error means and I can't seem to find an applicable explanation online. 我不知道该错误意味着什么,而且我似乎无法在网上找到适用的说明。 Other people who experienced this error seem to be doing something different... 其他遇到此错误的人似乎在做一些不同的事情。
I think this is just an issue with how I'm declaring the mapping in elasticsearch-rails
. 我认为这只是我如何在elasticsearch-rails
声明映射的问题。 Unfortunately, there isn't that much documentation around how this should look... Anyone have ideas? 不幸的是,关于它的外观并没有太多的文档...有人有想法吗?
I don't know who downvoted this question, but I think it's a totally useful question. 我不知道是谁对此问题投了反对票,但我认为这是一个完全有用的问题。
Turns out, when you don't need the path
for this. 原来,当您不需要此path
。 You can actually just set the routing part up like this: 您实际上可以像这样设置路由部分:
_routing: {type: 'user', required: 'true'})
I hope this helps someone. 我希望这可以帮助别人。
To the person who downvoted this question: maybe instead of making this community unwelcoming without reason, add a comment to explain why the question is bad. 对于拒绝该问题的人:也许不是让这个社区无缘无故地受欢迎,而是添加评论以解释为什么这个问题不好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.