Skip to content

Support unmapped fields in search 'fields' option. #63690

@jtibshirani

Description

@jtibshirani

We recommend omitting a field from the mappings when a user wants to avoid the indexing overhead, but still retrieve its values. This is usually accomplished by using an object field with enabled: false or dynamic: false. Since 'fields' is meant to be the central place to retrieve document content, it should allow for loading these unmapped values.

Longer-term we'd like to discourage users from having unmapped fields, and instead introduce lightweight ways to map data without indexing it. But in the meantime, we think it's valuable to support unmapped fields.

One proposal is to add a flag include_unmapped:

{
  "query": { "match_all": {} },
  "fields": [{
    "field": "headers.*",
    "include_unmapped": true
  }]
}

When include_unmapped is specified, the 'fields' option would do the following:

  1. Find all mapped leaf fields matching the patterns, collect + parse their values and add those to the hit. (This is what the option currently does).
  2. Also find all leaf fields in _source matching the patterns. If we find any fields that were not included in 1, add those to the hit as well. The fields are returned as-is, ignoring the 'format’ option.

The flag could default to 'false', and eventually be phased out as it becomes less common to have unmapped fields.

Some questions to consider:

  • Do we prefer adding a flag or just returning unmapped fields by default? It's always nice to avoid flags, and as we move towards a set-up where unmapped fields are rare, the distinction would become unimportant anyways. But the behavior is a bit hacky/ tricky, and I like that the flag indicates that it's 'non-standard' to be retrieving unmapped fields (in line with our longer term vision).
  • Would returning unmapped fields by default hurt fetch performance in the 'happy case' where all fields are mapped?
  • Is it fine to just return the unmapped values in a flattened list? This would drop structure in values like unmapped object arrays, ranges, etc.

Metadata

Metadata

Assignees

Labels

:Search/SearchSearch-related issues that do not fall into other categories>enhancementTeam:SearchMeta label for search team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions