Search code examples
ruby-on-railsrubypostgresqlelasticsearchsearchkick

How to use a "where not" clause with searchkick


I am using Searchkick with Elasticsearch to get products with a search term.

I am trying to add a WHERE NOT clause to it so it won't return any products with a regular_price that is null.

@products = Product.search(
        search,
        where: {
          regular_price: {
            not: "null" # I have also tried nil, both won't work
          }
        },
        page: params[:page],
        per_page: per_page,
      )

The search ignores my WHERE NOT clause.

I would also be grateful for some debugging tips for this.

Edit:

So I have tried to use the following but now it just returns every product that fits the search. Ignoring the WHERE NOT part of the search.

@products = Product.search(
        search,
        where: {
          regular_price: {
            _not: "null" 
          }
        },
        page: params[:page],
        per_page: per_page,
      )

UPDATE:

I have not found a solution to this issue and I moved on with a diffrent approach. By filtering out the products with a regular_price of 0.


Solution

  • Haven't found an answer yet. Because there aren't many products that I want to filter out with this query, I just filter them out while rendering.