Elastic Search – filter finding nothing disable other filters

  Kiến thức lập trình

My range filters are working perfectly when finding something, but when I target something that is not in the data, all filters are not respected anymore.

For example, I’m trying to get boardgames by age. I use a range filters that does work, like between 6 and 8 years old, or even between 8 and 8, because I have 8 in my database. I don’t have 7. If I target 7, all filters go out of range as you can see on the screenshots below.

Here is my query

{
  "from": 0,
  "size": 3,
  "query": {
    "bool": {
      "filter": [],
      "should": [],
      "must": [],
      "must_not": []
    }
  },
  "knn": {
    "field": "embedding",
    "query_vector": [
      (dense_vector)
    ],
    "k": 5,
    "num_candidates": 50,
    "boost": 0.5, 
    "filter": {
      "bool": {
        "filter": [
          {
            "range": {
              "tags.time.maxTime": {
                "lte": 30
              }
            }
          },
          {
            "range" : {
            "tags.age.minAge": {
              "gte": 7,
              "lte" : 7
            }
          }
          }
        ],
        "should": [],
        "must": [],
        "must_not": []
      }
    }
  }
}

bug with 7 in filters
working example

LEAVE A COMMENT