Skip to content

ESQL: Allow reading fields from source dynamically #115092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
flash1293 opened this issue Oct 18, 2024 · 4 comments
Open

ESQL: Allow reading fields from source dynamically #115092

flash1293 opened this issue Oct 18, 2024 · 4 comments
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@flash1293
Copy link
Contributor

flash1293 commented Oct 18, 2024

Description

Currently, it's not possible to directly read fields which are only available in source, but not mapped:

PUT my-restricted-index
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "a": {
        "type": "keyword"
      }
    }
  }
}

POST my-restricted-index/_doc
{
  "a":  "fsfd",
  "b": "xyz"
}

// fails with "Unknown column"
POST _query
{
  "query": "FROM my-restricted-index | WHERE b == \"xyz\""
}

However, it's possible to make this work using runtime fields:


PUT my-restricted-index/_mapping
{
    "runtime": {
      "b": {
        "type": "keyword"
      }
    }
}


// works now
POST _query
{
  "query": "FROM my-restricted-index | WHERE b == \"xyz\""
}

To allow users to both control their storage cost by not mapping and indexing rarely used fields and still being able to comfortably querying them via ESQL, there should be a way to instruct ESQL to read from source without having to deal with runtime fields. A possible syntax could look like this:

// works even without runtime field mapping
POST _query
{
  "query": "FROM my-restricted-index | EVAL b = FROM_SOURCE(\"b\", \"keyword\") | WHERE b == \"xyz\""
}

Ideally, there is a way for FROM_SOURCE to transparently leverage indexed fields if they exist - in this case the example above would check whether the field b is mapped - if not, it will retrieve it from source like the runtime field. If it's mapped as a keyword already, FROM_SOURCE becomes a no-op.

@flash1293 flash1293 added >enhancement needs:triage Requires assignment of a team area label Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) labels Oct 18, 2024
@elasticsearchmachine elasticsearchmachine removed the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Oct 18, 2024
@pxsalehi pxsalehi added the :Analytics/ES|QL AKA ESQL label Oct 18, 2024
@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) and removed needs:triage Requires assignment of a team area label labels Oct 18, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@nik9000
Copy link
Member

nik9000 commented Oct 21, 2024

Ideally, there is a way for FROM_SOURCE to transparently leverage indexed fields if they exist - in this case the example above would check whether the field b is mapped - if not, it will retrieve it from source like the runtime field. If it's mapped as a keyword already, FROM_SOURCE becomes a no-op.

That sounds pretty possible.

@jbaiera
Copy link
Member

jbaiera commented May 5, 2025

Throwing a +1 on this issue. The new failure store documents do not provide a mapping for their document source so that they can reliably index a failed document in the event of a mapping explosion or type conflict. Having the ability to supply runtime field support would greatly improve the user experience for searching this kind of data with ES|QL.

@nik9000
Copy link
Member

nik9000 commented May 5, 2025

There's a prototype available currently going under the name INSIST_🐔 which loads keyword fields. The goal is:

  1. If the field is already mapped at the type you asked for (currently only has keyword) then this is a noop
  2. If the field is mapped as another type then this is a cast
  3. If the field is not mapped then it's loaded from _source as that field type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

No branches or pull requests

5 participants