Search in a given index/type but filter by another type

hi,
can someone tell if the below is possible in ES and if yes, how?
lets say i have a twitter index with 2 types - tweets and user.

now i want to search for a keyword in the tweet but filter the results by
attributes of the corresponding user. e.g. give me all tweets that contain
"elasticsearch" in the tweet text and by users who have follower count >
100. the user_id of the tweet is the same as the id of the user type.

going through the documentation, i have a hunch that this is possible but i
am not able to figure it out.

thanks

On Mon, 2012-02-13 at 14:42 -0800, T Vinod Gupta wrote:

hi,
can someone tell if the below is possible in ES and if yes, how?
lets say i have a twitter index with 2 types - tweets and user.

now i want to search for a keyword in the tweet but filter the results
by attributes of the corresponding user. e.g. give me all tweets that
contain "elasticsearch" in the tweet text and by users who have
follower count > 100. the user_id of the tweet is the same as the id
of the user type.

going through the documentation, i have a hunch that this is possible
but i am not able to figure it out.

No, I'm afraid not. Currently it is not possible to do 'joins' in ES.
You would have to first query for a list of potential users, then use
the user_id's returned from there to query their tweets.

Alternatively, you could use parent/child relationships, where a tweet
is a child of the parent.

You would still need two queries:

  • give me all users whose children/tweets contain keywords "foo bar"
    and who have a follower count > 100
  • give me tweets which contain keywords "foo bar" and whose parent ID
    is in the list returned from query 1

clint

thanks

Thanks Clint. That was very helpful to know.

On Feb 14, 2:00 am, Clinton Gormley cl...@traveljury.com wrote:

On Mon, 2012-02-13 at 14:42 -0800, T Vinod Gupta wrote:

hi,
can someone tell if the below is possible in ES and if yes, how?
lets say i have a twitter index with 2 types - tweets and user.

now i want to search for a keyword in the tweet but filter the results
by attributes of the corresponding user. e.g. give me all tweets that
contain "elasticsearch" in the tweet text and by users who have
follower count > 100. the user_id of the tweet is the same as the id
of the user type.

going through the documentation, i have a hunch that this is possible
but i am not able to figure it out.

No, I'm afraid not. Currently it is not possible to do 'joins' in ES.
You would have to first query for a list of potential users, then use
the user_id's returned from there to query their tweets.

Alternatively, you could use parent/child relationships, where a tweet
is a child of the parent.

You would still need two queries:

  • give me all users whose children/tweets contain keywords "foo bar"
    and who have a follower count > 100
  • give me tweets which contain keywords "foo bar" and whose parent ID
    is in the list returned from query 1

clint

thanks