Query with exclusion list

I’m still a beginner and I’ve run into a task I don’t know how to solve.

We have a small system that has one index only. We store simple objects with many properties Most data types are simple keyword (or date) because these are the best for our searches. The number of documents is ~ 1 million.

The query is e.g. "I am looking for all women aged 25-50 who live in Budapest". (our queries are much more complex than this)

GET /contact/_search
{
  "query": {
      "bool": {
        "should": [
          {
              "term": {
                  "city": "Budapest"
              }
          },
          {
              "term": {
                  "gender": "female"
              }
          },
          {
              "range": {
                  "birthdate": {
                      "lte": "1995-05-14",
                      "gte": "1970-05-14"
                  }
              }
          }
        ]
      }
  }
}

This works very well for us, extremely fast.
Now, we want to query e.g. "I am looking for all women aged 20-50 who live in Budapest and do not have their ID on an exclusion list."

The exclusion list is currently e.g. a csv file with a hash column and e.g. 250,000 or 3,000,000 records.

Unfortunately, the exclusion list is never the same. This exclusion list is similar to NOT IN, NOT EXISTS in SQL. In one table the contacts, in another table the exclusion list: SELECT c. * FROM contact c WHERE c.age BETWEEN 20-50 AND c.city = 'Budapest' and NOT EXISTS (SELECT 1 FROM exlusion e WHERE c.md5hash = e.md5hash).

How could I achieve this result? What is the best method? Should I put the exclusion list in another index and then query the two indexes combined?

Thanks,
Laszlo

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.