# OR filter with boolean and ids

**URL:** <https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781>\
**Category:** Elasticsearch\
**Created:** [February 22, 2012, 9:02am UTC](https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781 "2012-02-22T09:02:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tommy/32/2980_2.png) [@tommy](https://discuss.elastic.co/u/tommy)\
**Post date:** [February 22, 2012, 9:02am UTC](https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781/1 "2012-02-22T09:02:08Z")

</div>

I'm trying to search through items, where some of them might be  
private.

If a item is private, only friends of item owner (array item.friends)  
may see the item. If it's not private, everyone can see it.

So my logic is: If item is not is\_private (is\_private=0) OR user id (4  
in my example) is in array item.friends, user can see the item.

Still i get no results. Every item is now set to is\_private=1, so I  
guess something is wrong with my ids filter.

// ---- 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": {}  
}  
}

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [February 22, 2012, 9:09am UTC](https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781/2 "2012-02-22T09:09:01Z")

</div>

Hi Tommy

On Wed, 2012-02-22 at 01:02 -0800, tommy wrote:

> I'm trying to search through items, where some of them might be  
> private.
> 
> If a item is private, only friends of item owner (array item.friends)  
> may see the item. If it's not private, everyone can see it.
> 
> So my logic is: If item is not is\_private (is\_private=0) OR user id (4  
> in my example) is in array item.friends, user can see the item.
> 
> Still i get no results. Every item is now set to is\_private=1, so I  
> guess something is wrong with my ids filter.

If you gist a working example (complete with curl statements) then I'd  
be happy to have a look at it. See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)

clint

> // ---- 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": {}  
> }  
> }

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tommy/32/2980_2.png) [@tommy](https://discuss.elastic.co/u/tommy)\
**Post date:** [February 22, 2012, 9:11am UTC](https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781/3 "2012-02-22T09:11:18Z")

</div>

Thanks for your reply.

It seems like i have misunderstood how ids work, allthough it should  
be pretty obvious by its name that it only searches for document ids,  
I somehow misunderstood this.

Sorry guys.

On Feb 22, 10:09 am, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Tommy
> 
> On Wed, 2012-02-22 at 01:02 -0800, tommy wrote:
> 
> > I'm trying to search through items, where some of them might be  
> > private.
> 
> > If a item is private, only friends of item owner (array item.friends)  
> > may see the item. If it's not private, everyone can see it.
> 
> > So my logic is: If item is not is\_private (is\_private=0) OR user id (4  
> > in my example) is in array item.friends, user can see the item.
> 
> > Still i get no results. Every item is now set to is\_private=1, so I  
> > guess something is wrong with my ids filter.
> 
> If you gist a working example (complete with curl statements) then I'd  
> be happy to have a look at it. Seehttp://www.elasticsearch.org/help
> 
> clint
> 
> > // ---- 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": {}  
> > }  
> > }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:38am UTC](https://discuss.elastic.co/t/or-filter-with-boolean-and-ids/6781/4 "2017-07-06T03:38:34Z")

</div>

Closed on July 6, 2017, 3:38am UTC


