Elasticsearch, getting the data within the range operator

24 Views Asked by At

I want to craft a query in Elasticsearch that fetches data from documents where the document_length field falls within a specified range and also includes documents where the document_length field is missing.

I tried to use this query, it returns all the data and does not take into consideration the given range of the document_length

Any ideas how to solve this issue ? Thank you

{
  "query": {
    "bool": {
      "should": [
        {
          "range": {
            "document_length": {
              "gte": min_length,
              "lte": max_length
            }
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "document_length"
              }
            }
          }
        }
      ]
    }
  }
}

I tried to use this query, it returns all the data and does not take into consideration the given range of the document_length

Any ideas how to solve this issue ? Thank you

{
  "query": {
    "bool": {
      "should": [
        {
          "range": {
            "document_length": {
              "gte": min_length,
              "lte": max_length
            }
          }
        },
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "document_length"
              }
            }
          }
        }
      ]
    }
  }
}
0

There are 0 best solutions below