quickwit-oss / quickwit

Cloud-native search engine for observability. An open-source alternative to Datadog, Elasticsearch, Loki, and Tempo.
https://quickwit.io
Other
8.04k stars 328 forks source link

ES range query with malformed bounds causes searcher to panic #3790

Closed imotov closed 1 year ago

imotov commented 1 year ago

Describe the bug

An ES-compatible range query with the lower bound higher then the upper bound causes the searcher to panic.

{
    "query": {
        "range": {
            "some_u64_field": {
                "gte": 15,
                "lt": 0
            }
        }
    }
}

Steps to reproduce (if applicable)

#!/usr/bin/env bash

set -e

URL=http://localhost:7280
QW_URL=$URL/api/v1
ES_URL=$QW_URL/_elastic
INDEX_ID=my-test

curl -XDELETE $QW_URL/indexes/$INDEX_ID

curl -XPOST $QW_URL/indexes  -H "Content-Type: application/json" -d '{
    "version": "0.5",
    "index_id": "'$INDEX_ID'",
    "doc_mapping": {
        "field_mappings": [
            {
                "name": "body",
                "type": "text"
            },
            {
                "name": "size",
                "type": "u64",
                "fast": true
            }

        ]
    },
    "indexing_settings": {
      "commit_timeout_secs": 1
    }
}'

curl -XPOST $QW_URL/$INDEX_ID/ingest\?commit=force -H 'Content-Type: application/json' -d '
{"body":"test zero", "size": 10}
{"body":"test one", "size": 20}
'

curl -XPOST $ES_URL/$INDEX_ID/_search -H 'Content-Type: application/json' -d '{
    "query": {
        "range": {
            "size": {
                "gte": 15,
                "lt": 0
            }
        }
    }
}'

Expected behavior The query should return no results.

Configuration: Current main branch.

PSeitz commented 1 year ago

I don't get a panic, but a wrong result. The lt=0 is ignored

➜  asdf curl -XPOST http://localhost:7280/api/v1/_elastic/gharchive/_search -H 'Content-Type: application/json' -d '{
            "query": {
                "range": {
                    "size": {
                        "gte": 15,
                        "lt": 0
                    }
                }
            }
        }'

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "hits": [
      {
        "_source": {"body":"test one","size":20},
        "fields": {
          "body": "test one",
          "size": 20
        }
      }
    ]
  }
}                                                                                                                               
imotov commented 1 year ago

Here is what I just did:

PSeitz commented 1 year ago

Ah okay, the difference is the debug mode, which adds overflow checks.