Ah, that looks along the lines of what I'm trying to do, thanks.
I had tried something similar previously but was confused by the note
in the docs saying:
"The filter object can hold only filter elements, not queries", so had
given up trying to get it working as part of the filter!
What does that note actually mean?
The docs also mention that filters don't perform any scoring, so is
there a benefit of nesting the query in a constant_score in your
example?
I've managed to get the following working now:
{
"query" => {
"filtered" => {
"query" => {
"query_string" => { "query" => "test" }
},
"filter" => {
"query" => {
"query_string" => {
"default_field" => "document_id",
"query" => "4c31d38acf02a31548000009 OR 4c31d38acf02a31548000008"
}
}
}
}
}
}
Thanks for the help!
On Tue, Aug 24, 2010 at 6:56 PM, Paul ppearcy@gmail.com wrote:
Hi Richard,
I have a similar situation where for any user we construct a query
string that enforces what they are entitled to. This query string can
be arbitrarily complex. Just taking that query string and wrapping it
in a filter seems to work very well. So, my final query typically ends
up looking like:'filtered' : { 'query' : { 'query_string' : {'query':mainquery} }, 'constant_score' : { 'filter' : { 'query' : { 'query_string' : {'query':userentitlements} } } } }So you can keep doing similar to what you are doing, but this query
structure yields good caching on the user entitlements part.Not sure if this is optimal, but is working quite well in my
performance testing thus far.Regards,
PaulOn Aug 24, 11:43 am, Richard Livsey liv...@gmail.com wrote:
Each user in our app can see a subset of the documents based on a
number of conditions (permissions etc...) and I'm wondering what the
best approach to building a restricted query would be.Andrei asked a similar question about restricting the query with
boolean vs filters in which filters came up as the most efficient
method:http://elasticsearch-users.115913.n3.nabble.com/Boolean-query-vs-filt...However in our data model we don't have a single field which we can
filter by, it's more a case of getting a list of all the IDs of
documents the user can access and then searching them.Eg, modelled as a boolean query, which works but isn't very elegant
and I can see it having issues with performance as the query grows:{ :query => { :bool => { :must => [ { :query_string => { :query => params[:q] } }, { :query_string => { :default_field => "id", :query => accessible_ids.join(" OR ") } } ] } } }Is there a way of performing a term query against an array of terms so
that I could convert this to a filter?
Or is there a better way of doing this that someone knows of?