Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

Just replace "null" with nil and it would filter out the products that don't have regular_price.

over 4 years ago · Santiago Trujillo Report

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!