【发布时间】:2017-01-21 00:04:12
【问题描述】:
我正在使用 ES 1.4、Rails 5 和 Mongoid 6。我也是 mongoid-elasticsearch gem,我认为它不相关,但如果我错了,请包含它。
我有一个案例模型。当我运行此查询时,一切正常,这是查询:
GET _search
{
"query":{
"filtered":{
"query":{
"query_string":{
"query":"behemoth"
}
}
}
}
}
这是一个结果,注意 organization_id:
hits": [
{
"_index": "cases",
"_type": "case",
"_id": "57d5e583a46100386987d7f4",
"_score": 0.13424811,
"_source": {
"basic info": {
"first name": "Joe",
"last name": "Smith",
"narrative": "behemoth"
},
"organization_id": {
"$oid": "57d4bc2fa461003841507f83"
},
"case_type_id": {
"$oid": "57d4bc7aa461002854f88441"
}
}
}
看到组织 id 的“$oid”是怎么回事?那是因为在我的案例 as_indexed_json 方法中,我有:
["organization_id"] = self.case_type.organization.id
我认为过滤器不起作用 b/c Mongoid 以某种方式添加了该子项 $oid。所以我的下一个想法是,我就把它变成一个字符串:
["organization_id"] = self.case_type.organization.id.to_s
但这会引发错误:
{"error":"MapperParsingException[object mapping for [case] tried to parse as object, but got EOF, has a concrete value been provided to it?]","status":400}
任何人都知道如何 A) 使用 mongo id 作为过滤器,或 B) 获取 ES 所需的信息,这样它就不会像上面那样抱怨?
感谢您的帮助, 凯文
【问题讨论】:
标签: ruby-on-rails elasticsearch mongoid