2
我試圖搜索項目,其中一些可能是私人的。彈性搜索 - 或布爾和ID篩選器
如果一個項目是私人的,只有項目所有者(數組item.friends)的朋友可以看到該項目。 如果它不是私人的,每個人都可以看到它。
所以我的邏輯是: 如果產品不is_private
(is_private = 0)OR 用戶ID(4在我的例子)是在陣列item.friends
,用戶可以看到該項目。
我還沒有得到任何結果。每個項目現在設置爲is_private
= 1,所以我想我的ID過濾器有問題。
有什麼建議嗎?
// ---- 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": {}
}
}
你絕對正確!對於那個很抱歉。現在,有沒有可以在我的「朋友」數組內搜索的過濾器? – fortysixandtwo 2012-02-22 09:07:38
一個簡單的術語過濾器應該這樣做。謝謝你的協助。 – fortysixandtwo 2012-02-22 09:12:23