Search code examples
ruby-on-railselasticsearchsearchkick

Query of searchkick get wrong result


Query of searchkick get wrong result. I have this one record in db:

2.2.0 :047 > Product.first
  #<Product id: 1, title: "Ball", description: "<p>Ball</p>\r\n", price: 10, material: "lalala", created_at: "2015-04-21 04:30:53", updated_at: "2015-04-21 04:30:53", preview: "images__1_.jpg", count: 20> 

in controller Product and action search i have this code:

    def search
          @products = Product.search "*", where:
            {
              count: 10..18
            }
      end

and after this, a get result, that the with this values, count is exist. But in db count = 20. And all time, get wrong result. I don't know why?


Solution

  • I get not correct result, 'cause i don't have hash, in model and need reindex of Model.

    In model:

    def search_data
        {
          count: count,
          price: price,
          title: title,
          category_id: categories.map($:id)
        }
    end
    

    and after that, in rails console wrote:

    Product.reindex