如何建立与elasticsearch护栏映射路由

问题描述:

我试图使用tire宝石等值与elasticsearch-rails宝石的Item模型转换的映射:如何建立与elasticsearch护栏映射路由

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'}) 

我希望这有助于某人。

对于那些低估了这个问题的人:也许而不是让这个社区没有理由不接受,增加一个评论来解释为什么这个问题是不好的。