Bool filter not matching on range query


(kikster) #1

I'm submitting a filtered query with the following filter (I convert
the hash into json before sending it)

        :filter => {
          :bool => {
            :must_not => {
              :term => {
                "show" => 0
              }
            },
            :must => {
              :range => {
                :price => {
                  :from => 0, :to => 20
                }
              }
            },
            :must => {
              :nested => {
                :path => "regions", :query => {
                  :term => {
                    "id" => var_1
                  }
                }
              }
            }
          }
        }

Documents get returned that meet all criteria except the "range" one.
Do I have to do something special to match fields that have a number?
Currently the "price" field is of type long....there's a snippet of
the document's mapping below.

"price":{"type":"long"},


(kikster) #2

Got it working with this exact same code. Not sure why it wasn't
working before, but I'm positive it was something I was doing wrong.

On Aug 17, 4:21 pm, Chris christopherdavidoliva...@gmail.com wrote:

I'm submitting a filtered query with the following filter (I convert
the hash into json before sending it)

        :filter => {
          :bool => {
            :must_not => {
              :term => {
                "show" => 0
              }
            },
            :must => {
              :range => {
                :price => {
                  :from => 0, :to => 20
                }
              }
            },
            :must => {
              :nested => {
                :path => "regions", :query => {
                  :term => {
                    "id" => var_1
                  }
                }
              }
            }
          }
        }

Documents get returned that meet all criteria except the "range" one.
Do I have to do something special to match fields that have a number?
Currently the "price" field is of type long....there's a snippet of
the document's mapping below.

"price":{"type":"long"},


(kikster) #3

Also, what's weird is that a query that uses the exact same filter,
but omits the "nested" query works. Now I'm starting to think it has
something to do with having multiple bool "must" clauses in a bool
query. Why would including the last must clause cause the query to no
longer match on a price range?

On Aug 17, 4:21 pm, Chris christopherdavidoliva...@gmail.com wrote:

I'm submitting a filtered query with the following filter (I convert
the hash into json before sending it)

        :filter => {
          :bool => {
            :must_not => {
              :term => {
                "show" => 0
              }
            },
            :must => {
              :range => {
                :price => {
                  :from => 0, :to => 20
                }
              }
            },
            :must => {
              :nested => {
                :path => "regions", :query => {
                  :term => {
                    "id" => var_1
                  }
                }
              }
            }
          }
        }

Documents get returned that meet all criteria except the "range" one.
Do I have to do something special to match fields that have a number?
Currently the "price" field is of type long....there's a snippet of
the document's mapping below.

"price":{"type":"long"},


(system) #4