【发布时间】:2012-03-12 13:47:59
【问题描述】:
我正在尝试搜索项目,其中一些可能是私有的。
如果一个项目是私有的,只有项目所有者的朋友(数组 item.friends)可以看到这个项目。 如果它不是私人的,每个人都可以看到它。
所以我的逻辑是:
如果项目 not is_private (is_private=0) OR 用户 ID(在我的示例中为 4)在数组 item.friends 中,则用户可以看到该项目。
我仍然没有得到任何结果。现在每个项目都设置为is_private=1,所以我猜我的 ids 过滤器有问题。
有什么建议吗?
// ---- Mapping
{
"item": {
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"created": {
"type": "date"
},
"location": {
"properties": {
"location": {
"type": "geo_point"
}
}
},
"is_proaccount": {
"type": "integer"
},
"is_given_away": {
"type": "integer"
},
"is_private": {
"type": "integer"
},
"friends": {
"type": "integer",
"index_name": "friend"
}
}
}
}
// ----- Example insert
{
"name": "Test",
"description": "Test",
"created": "2012-02-20T12:21:30",
"location": {
"location": {
"lat": "59.919914",
"lon": "10.753414"
}
},
"is_proaccount": "0",
"is_given_away": "0",
"is_private": 1,
"friends": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
]
}
// ----- Query
{
"from": 0,
"size": 30,
"filter": {
"or": [
{
"bool": {
"must": [
{
"term": {
"is_private": 0
}
}
]
}
},
{
"ids": {
"values": [
4
],
"type": "friends"
}
}
]
},
"query": {
"match_all": {}
}
}
【问题讨论】:
标签: elasticsearch