Skip to content

[data.indexPattern][data.search.searchSource] Remove indexPattern.getComputedFields. #85162

@lukeelmers

Description

@lukeelmers

Currently the index pattern class has a getComputedFields method which returns docvalue, stored, and scripted fields for a particular pattern. This method is only used by high level search (search source), and in discover.

Now that we've added support for the search fields API in search source, this method is less relevant and could probably be removed.

Here's a breakdown of each of the properties it returns and how they could be replaced:

1. docvalue fields
These were only used for ensuring that time fields were all requested in a format that Kibana understands (since ES supports more date formats than Kibana/momentjs knows how to parse). This was previously done using docvalue_fields, but since #82383 we are now requesting these formatted fields using the fields API. So getComputedFields().docvalueFields is still being used as a convenient way to access these fields, however the naming is confusing as it no longer has anything to do with docvalue fields.

Here's the logic that index patterns uses:

    const docvalueFields = reject(this.fields.getByType('date'), 'scripted').map(
      (dateField: any) => {
        return {
          field: dateField.name,
          format:
            dateField.esTypes && dateField.esTypes.indexOf('date_nanos') !== -1
              ? 'strict_date_time'
              : 'date_time',
        };
      }
    );

This could be moved into a different method or some type of static helper utility which is then used to retrieve all fields of type date with formats injected. e.g.

indexPattern.getFormattedDateFields() => Array<{ field: string; format: string }>
// or
getFormattedDateFields(fields: IndexPatternField[]) => Array<{ field: string; format: string}>

2. stored fields
We need to audit whether these are actually needed at all. getComputedFields always hardcodes this as ['*']. Search source will either request ['*'] or specific field names if the user provides them.

My understanding is that the fields API does not return stored fields, but we should test and determine whether we still need this feature at all in search source. Either way I don't think we really need it in getComputedFields

3. scripted fields
Search source could be switched over to using indexPattern.getScriptedFields instead, which is what getComputedFields does internally. There's no reason why we need to use getComputedFields for this.

cc @timroes @mattkime

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature:Data ViewsData Views code and UI - index patterns before 8.0Feature:SearchQuerying infrastructure in KibanaIceboxTeam:DataDiscoveryDiscover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t//choreimpact:lowAddressing this issue will have a low level of impact on the quality/strength of our product.loe:smallSmall Level of Efforttechnical debtImprovement of the software architecture and operational architecture

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions