2
私はアイテムを検索しようとしていますが、そのうちのいくつかはプライベートであるかもしれません。弾性検索とブール値とidsを持つORフィルタ
アイテムがプライベートの場合、アイテム所有者の友人(配列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": {}
}
}
を参照してください。あなたは絶対に正しいです!申し訳ありません。さて、私の "friends"配列内を検索できるフィルタはありますか? – fortysixandtwo
簡単な用語フィルタを使用します。私を助けてくれてありがとう。 – fortysixandtwo