Filtering documents based on a boolean value

I have been banging my head against the wall for hours to try and
figure out how to filter a document based on the value of a boolean.
It seems straight forward, but these queries do not seem to be
working. Here is the query I'm using:

    :query => {
      :filtered => {
        :query => {
          :custom_score => {
            :query => {
              :bool => {
                :should => {
                  :query_string => {
                    :query => "query",
                    :fields => ["field1", "field2"]
                  }
                },
                :must => {
                  :nested => {
                    :path => "path", :query => {
                      :flt => {
                        :fields => ["field3"], :like_text =>

"query"
}
}
}
}
}
},
:script => "_score * doc['admin_score'].value"
}
},
:filter => {
:bool => {
:must_not => {
:term => {
:show => 0
}
}
}
}
}
},
:size => 20

I convert this syntax into JSON before sending. I only want to return
results where object.show == true, but documents where show == false
are getting through the filter. Here's what the mapping for the
"show" field:

"show":{"type":"boolean"}

What am I doing wrong???

And here's a gist of the above query hash...

Here's a gist of the above query: https://gist.github.com/1158523

Note: I'm using ruby and use MultiJson.encode to convert the above
hash into JSON

Ok so I figured it out, turns out wrapping a filter inside a bool
yields the wrong functionality and simply putting the term clause
works...learning the hard way ftw.

On Aug 19, 7:35 pm, Chris christopherdavidoliva...@gmail.com wrote:

Here's a gist of the above query: 1158523’s gists · GitHub

Note: I'm using ruby and use MultiJson.encode to convert the above
hash into JSON

Hi Chris

On Fri, 2011-08-19 at 23:22 -0700, Chris wrote:

Ok so I figured it out, turns out wrapping a filter inside a bool
yields the wrong functionality and simply putting the term clause
works...learning the hard way ftw.

Filters don't use the 'bool' QUERY. Instead, they can be combined with
and,or,not FILTERs.

So you could rewrite your filter as:

:filter => {
:not => { :term => { :show => 0 }}
}

clint

I implemented this change, but now it appears documents are not being filtered properly. Documents where show == false are still getting through.

Here's the query.

This has been a persistent problem that I'm not sure how to fix.