Search in Elasticsearch objects from non blocked user


(rrader) #1

In Elaasticsearch we have 3 collections, users, products and blocked_users.

users{id, first_name, last_name, ...}
products{id, user_id, title, ...}
blocked_users{user_id, blocked_user_id}

I want to search products by title, but I don't want to show products oof blocked users.

How should be query?


(David Pilato) #2

You can't really do "joins" in elasticsearch.

You may want to look at parent/child feature but that's not may be straightforward.

I think it would be better to have a single data structure products like:

PUT products/doc/1
{
  "title": "Title",
  "user": {
    "first_name": "First",
    "last_name": "Last",
    "blocked": true
  } 
}

(rrader) #3

But for some users it can be blocked, and for others they will be not blocked, it depends if logged user blocked product's user.


(David Pilato) #4

Can you give an example with the model you sent?

users{id, first_name, last_name, ...}
products{id, user_id, title, ...}
blocked_users{user_id, blocked_user_id}

(rrader) #5

user[
{id: 1, first_name: "John", last_name:"Snow", ...}
{id: 2, first_name: "Sarah", last_name:"Connor", ...}
{id: 2, first_name: "Arnold", last_name:"Schwarzenegger", ...}
]

products[
{id: 1, user_id: 3, title:"Apple"}
]

blocked_users[
{user_id: 2, blocked_user_id: 3} // this mean user with id 2 blocked user with id 3
]

so, when user with id 1 search he will get a response with 1 product
when user with id 2 search 0 products is expected, because product user id is 3, but user with id 2 blocked this user


(David Pilato) #6

Would that work then?

PUT products/doc/1
{
  "title": "Title",
  "user": {
    "id": "3",
    "first_name": "First",
    "last_name": "Last",
    "blocked_users": [ "2" ]
  } 
}

Which basically means that as user 2, I won't see that product as I blocked all the products that created user 3.


(system) #7

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.