elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.65k stars 8.23k forks source link

[Index pattern] Add support for object runtime field "subFields" #99177

Closed sebelga closed 2 years ago

sebelga commented 3 years ago

:warning: [EDIT]: I've created https://github.com/elastic/kibana/discussions/99462 to discuss this proposal. Let's use that discussion to raise concerns and suggest alternatives/modifications. Once we have committed on the changed required I will update the description of the issue.

Problem

Object runtime fields give the user the possibility to declare multiple sub fields inside a parent object through a script. For that the user will emit multiple value from the painless script as a set of key/value pairs. The problem is: this single runtime field, once saved in the Kibana index pattern, will appear as one field and none of the sub fields will be exposed. When an app (Lens, Discover) will ask for the list of fields on the index pattern it will then receive this top object runtime field and none of the associated sub fields.

Proposal

I suggest the following:

New subFields prop

The field editor returns a new optional subFields property on the runtime field (following the naming convention in place for concrete fields)

{
  "name": "myObject",
  "type": "object",
  "script": "// script to emit multiple sub fields",
  "format": // Will never be there for object runtime fields
  "subFields": {
    "foo": {
      "format": { // format definition },
      "priority: 1
    },
    "bar": {
      "format": { ... },
      "priority": 2,
    }
  }
}

Add a parent (optional) parameter to index pattern field definition

this.fields.add({
  name,
  runtimeField,
  type: castEsToKbnFieldTypeName(runtimeField.type),
  aggregatable: true,
  searchable: true,
  count: 0,
  readFromDocValues: false,
  parent: 'myRuntimeFieldObject' // New
});

This will allow us the normal CRUD operation like other runtime fields:

Support format for sub fields

We also need to update the logic to add the format definition for each subField to the index pattern attributes (here: index pattern field editor)

cc @mattkime @stacey-gammon

elasticmachine commented 3 years ago

Pinging @elastic/kibana-app-services (Team:AppServices)

elasticmachine commented 3 years ago

Pinging @elastic/es-ui (Team:Elasticsearch UI)

timroes commented 3 years ago

All that sounds reasonable for me, I guess my only question would be: should the parent flag also be written for non runtime fields object fields, or will it be a specific thing for runtime fields?

sebelga commented 3 years ago

All that sounds reasonable for me, I guess my only question would be: should the parent flag also be written for non runtime fields object fields, or will it be a specific thing for runtime fields?

Any field could potentially define it but for the time being it would only be set when creating runtime fields.

sebelga commented 3 years ago

Fixed in https://github.com/elastic/kibana/pull/110226