Skip to content
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

Universal fields API #61388

Open
stu-elastic opened this issue Aug 20, 2020 · 7 comments
Open

Universal fields API #61388

stu-elastic opened this issue Aug 20, 2020 · 7 comments
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team

Comments

@stu-elastic
Copy link
Contributor

stu-elastic commented Aug 20, 2020

Rather than requiring users to use standard list and map objects to deal with field access, update, etc. We should expose an API that facilitates these operations while making it easy to handle fields that do not currently exist.

Users should be able to use the API to access fields in either doc values or source, where the implementation can pick the most performant option (doc values).

@stu-elastic stu-elastic added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Aug 20, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Scripting)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Aug 20, 2020
@jimczi jimczi added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Aug 20, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@jpountz
Copy link
Contributor

jpountz commented Sep 4, 2020

Users should be able to use the API to access fields in either doc values or source, where the implementation can pick the most performant option (doc values).

I was actually hoping to go the other way around. With runtime fields coming, there's much less incentive to leave fields unmapped and I hope the more common practice will be to dynamically map fields as runtime fields, e.g. with a dynamic template:

PUT myindex
{
  "mappings": {
    "dynamic_templates": [{
      "runtime_by_default": {
        "match_mapping_type": "*",
        "mapping": {
          "type": "runtime",
          "runtime_type": "{dynamic_type}"
        }
      }
    }],
    ...
  }
}

If we do that, then we won't even need _source as the responsibility of reading data from the _source and exposing it the right way will be the responsibility of the mappings rather than the responsibility of scripts. And _source will only be ever needed when the fact that doc flattens the JSON structure proves problematic, which hopefully means rarely.

@rjernst
Copy link
Member

rjernst commented Sep 4, 2020

@jpountz How do you envision that working for nested documents? Currently nested docs cannot be accessed through doc values.

@jpountz
Copy link
Contributor

jpountz commented Sep 6, 2020

I don't know how that could work but I wonder if this is really a scripting problem as queries and aggregations have the same limitation: you can't leverage nested fields unless you enter a nested context via the nested query or the nested aggregation. So I'd be keen to think about the nested problem more broadly.

@rjernst
Copy link
Member

rjernst commented Sep 6, 2020

It's a problem in scripting for ingest, where a user may want to manipulate nested docs in source. I agree on the search side nested queries/aggs should be used.

@rjernst rjernst added the needs:triage Requires assignment of a team area label label Dec 3, 2020
@stu-elastic stu-elastic removed the needs:triage Requires assignment of a team area label label Dec 9, 2020
stu-elastic added a commit that referenced this issue Aug 4, 2021
Adds minimal fields API support to sort and score scripts.

Example: `field('myfield').getValue(123)` where `123` is the default if the field has no values.

Refs: #61388
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Aug 4, 2021
Adds minimal fields API support to sort and score scripts.

Example: `field('myfield').getValue(123)` where `123` is the default if the field has no values.

Refs: elastic#61388
Backport: 6c02a6c
stu-elastic added a commit that referenced this issue Aug 4, 2021
Adds minimal fields API support to sort and score scripts.

Example: `field('myfield').getValue(123)` where `123` is the default if the field has no values.

Refs: #61388
Backport: 6c02a6c
@javanna javanna removed :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team labels Apr 26, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

No branches or pull requests

7 participants