【发布时间】:2020-04-23 23:29:28
【问题描述】:
我在一个名为inventory 的索引中配置了两个文档。
- 个人资料(有用户和手机信息)
- p2p 关系
库存索引映射属性如下:
{
"mappings": {
"properties": {
"type": {"type": "keyword"},
"id": {"type": "keyword"},
"sourceId": {"type": "keyword"},
"targetId": {"type": "keyword"},
"firstName": {"type": "text"},
"lastName": {"type": "text"},
"createdBy": {"type": "text"},
"p_type": {"type": "text"},
"model": {"type": "text"},
"OS": {"type": "keyword"}
}
}
}
个人资料有以下信息
用户:
{ "type":"profile", "id" : "user1", "p_type" : "user", "firstName" : "Ashok", "lastName" : "S" }
{ "type":"profile", "id" : "user2", "p_type" : "user", "firstName" : "Arun", "lastName" : "V" }
手机:
{ "type":"profile", "id" : "mobile1", "p_type" : "mobile", "model" : "samsung", "OS" : "Android" }
{ "type":"profile", "id" : "mobile2", "p_type" : "mobile", "model" : "iPhone", "OS" : "iOS" }
p2p-relation有哪个用户使用了哪个手机信息:
{ "type":"p2p-relation", "id" : "user1-owns-mobile1", "sourceId" : "user1", "targetId" : "mobile1", "createdBy" : "admin" }
{ "type":"p2p-relation", "id" : "user1-owns-mobile2", "sourceId" : "user1", "targetId" : "mobile2", "createdBy" : "admin" }
在我们的业务案例中,我们需要检索用户拥有的 android/iOS 手机列表,该列表是我们从客户那里获得的输入。
也就是说,如果 user1 请求 /mymobiles?query=os==Android ,它应该将其翻译成 ES 并期待
{ “type”:“profile”,“id”:“mobile1”,“p_type”:“mobile”,“model”:“samsung”,“OS”:“Android”}
作为结果,如果 user2 请求相同,它应该返回空。
我尝试过查询和布尔。但它只在单个文档中搜索。如何在弹性搜索中实现这一点?
【问题讨论】:
-
你能分享你的索引映射吗?这些
types、profile和p2p-relation是同一个索引的一部分,或者它们是不同类型的ES索引,你使用的是哪个版本的elastic? -
“profile”和“p2p-relation”都存储在同一个索引中。并使用 7.4.0 版本。
-
用索引映射更新了问题。
-
我在你的映射中没有看到
p_type -
对不起。我会在映射中更新它。 p_type、模型和操作系统也存在于映射中。
标签: java elasticsearch elasticsearch-query