elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
876 stars 24.81k forks source link

ESQL: "expr::text" cast returning a keyword #111537

Closed ivancea closed 1 week ago

ivancea commented 3 months ago

The <x>::text inline cast depends on ToString to make the cast, which always returns keyword. It could make sense in ToString, but a <x>::text cast is expected to return a text.

Reproduce with:

Query:

ROW txt="abc"::text

Result:

{
  "columns": [
    {
      "name": "txt",
      "type": "keyword"
    }
  ],
  "values": [
    [
      "txt"
    ]
  ]
}

Note that the column type is "keyword".

Another example

Index test with mapping:

{
  "text_field": {
    "type": "text"
  }
}

Query:

FROM test
| eval x = CASE(true, text_field, "txt"::text)

Result:

{
  "error": {
    "root_cause": [
      {
        "type": "verification_exception",
        "reason": "Found 1 problem line 4:12: third argument of [CASE(true, text_field, \"txt\"::text)] must be [text], found value [\"txt\"::text] type [keyword]"
      }
    ],
    "type": "verification_exception",
    "reason": "Found 1 problem line 4:12: third argument of [CASE(true, text_field, \"txt\"::text)] must be [text], found value [\"txt\"::text] type [keyword]"
  },
  "status": 400
}
elasticsearchmachine commented 3 months ago

Pinging @elastic/es-analytical-engine (Team:Analytics)

ivancea commented 2 months ago

After some discussion, we're going with adding a warning on use, that tells the users that the cast may not be doing what they expect