Is there any way to construct a filter that will filter out any documents 
that match any values in an array from, say, 2 different fields?

Imagine a document that stores friendships/recommendations/etc, where the 
document might store ids for each user as user_1 and user_2, and then other 
information in whatever other fields you'd need.  The important thing is 
the user_1 and user_2 fields, but here's an idea of what the doc might look 
like:

{
  user_1: 12345,
  user_2: 23456,
  facebook_friends: true,
  twitter_friends: false,
  comments: "blahblahblahh"
}

I would like to execute a query that returns a set of documents but 
excludes any friendships for a list of user ids.  These excluded user_ids 
might be listed as user_1 in some docs, but might be listed as user_2 in 
others.  I can easily construct a terms query for each field that will say 
"exclude where user_1 is any of these values AND THEN exclude where user_2 
is any of these values" but what I'd like to do is say "exclude where 
either user_1 or user_2 are any of these values".

Right now I have to do this:

{
  query: {
    filtered: {
      query: {
        // whatever...
      },
      filter: {
        bool: {
          must_not: [
            {
              terms: { 
                user_1: [12345, 23456]
            },
            {
              terms: { 
                user_2: [12345, 23456]
            }
          ]
        }
      }
    }
  }
}

Some of these filters end up getting pretty large, and I'd like to be able 
to avoid duplicating the array within the same query if I can.  Something 
like this would be awesome, but I can't figure out if there's any way to do 
it:

{
  query: {
    filtered: {
      query: {
        // whatever...
      },
      filter: {
        not: {
          multi_match: {
            terms: ["user_1", "user_2"],
            values: [12345, 23456]
          }
        }
      }
    }
  }
}

Thanks,
-Mike

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/4fcef91a-3f44-4452-acb3-dc704c8c2005%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to