OR filter with boolean and ids


(tommy) #1

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


(Clinton Gormley) #2

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


(tommy) #3

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


(system) #4