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

[Discover] Add support for unmapped fields using the fields API #89074

Merged
merged 94 commits into from
Feb 3, 2021

Conversation

majagrubic
Copy link
Contributor

@majagrubic majagrubic commented Jan 23, 2021

Summary

Fixes #88192.
This PR adds support for unmapped fields using the new fields API. The logic we discussed to implement this is as follows:

  1. There is a switch in the UI with the deprecation notice; the switch is on by default for existing saved searches; off by default for new saved searches
  2. To determine if it's an existing (pre 7.12) saved search, we need a data migration

Current flow:
(notice that for same index pattern unmapped fields don't show if it's a new saved search, but they show up when you load a pre-existing one)
unmapped_fields

How to test this?

  1. Before pulling the branch, create an index in ES with unmapped fields. Eg:
PUT /my-test-index
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "field1": { "type": "text" }
    }
  }
}

PUT /my-test-index/_doc/1
{
  "field1": "Some blob of text",
  "field2": "Some other text"
}

PUT /my-test-index/_doc/2
{
  "field1": "Some blob of text",
  "field2": "Some other text"
}

PUT /my-test-index/_doc/3
{
  "field1": "Some blob of text",
  "field3": 12
}

PUT /my-test-index-2
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
     "dynamic": false
  }
}

PUT /my-test-index-2/_doc/1
{
  "field1": "Some blob of text",
  "field2": "Some other text"
}

PUT /my-test-index-2/_doc/2
{
  "field1": "Some blob of text",
  "field2": "Some other text"
}

PUT /my-test-index-2/_doc/3
{
  "field4": "Some blob of text",
  "field5": 12
}


PUT /my-test-index-2/_doc/4
{
  "field4": "Some blob of text",
  "field5": 12
}
  1. Create an index pattern from the newly created index
  2. Go to Discover, select the index pattern created under 2
  3. Save the existing saved search
  4. Pull the branch, restart Kibana
  5. Observe how unmapped fields are behaving

Checklist

Delete any items that are not applicable to this PR.

For maintainers

lukeelmers and others added 30 commits November 2, 2020 10:05
@kertal
Copy link
Member

kertal commented Feb 1, 2021

@elasticmachine merge upstream

@@ -0,0 +1,450 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're using

test/functional/fixtures/es_archiver/unmapped_fields

for your functionals, you can delete

test/functional/fixtures/es_archiver/data

*/
unmappedFieldsConfig?: {
/**
* callback funtction to change the value of `showUnmappedFields` flag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: funtction -> function

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking pretty good 👍 (so far just minor remarks) , while testing I've found one case that I think needs adaptation or discussion. when adding a pre712 saved search, unmapped fields are displayed in Discover, but not when using the saved search on a Dashboard:

saved-search-pre712.mp4

@majagrubic
Copy link
Contributor Author

@elasticmachine merge upstream

@majagrubic
Copy link
Contributor Author

@kertal I fixed the embeddable so that it works with the new API now

@majagrubic majagrubic requested a review from kertal February 3, 2021 07:01
@kertal
Copy link
Member

kertal commented Feb 3, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 413.4KB 417.1KB +3.7KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 69.1KB 69.1KB +47.0B

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/development-plugin-saved-objects.html#_mappings

id before after diff
search 9 10 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM 👍, embeddable now works. Tested locally using Chrome/Safari, works as expected. One note: using the Angular legacy grid, rendering of records in the table are not updated when there's a refetch when switching the Show unmapped. This is due to the internal Angular caching works. There's no easy workaround here than: switching to EuiDataGrid. There it works, so this should not block this PR.

@@ -298,6 +306,20 @@ export class SearchEmbeddable
this.services.uiSettings.get(SORT_DEFAULT_ORDER_SETTING)
)
);
if (useNewFieldsApi) {
searchSource.removeField('fieldsFromSource');
const fields: Record<string, any> = { field: '*' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: another any that could bite the dust

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address this in the next PR

@majagrubic majagrubic requested a review from gchaps February 3, 2021 12:58
@majagrubic majagrubic merged commit c6be748 into elastic:master Feb 3, 2021
@majagrubic majagrubic deleted the unmapped-fields branch February 3, 2021 15:05
majagrubic pushed a commit that referenced this pull request Feb 4, 2021
…#89074) (#90184)

* [Discover] Add support for unmapped fields using the fields API (#89074)

* Add search source to example plugin.

* Add uiSetting for fields API.

* Update SearchSource to support fields API.

* [PoC] reading from the fields API in Discover

* Add N fields as a default column

* Make fields column non-removeable

* Do not add 'fields' to state

* Remove fields from app state and read from source when needed

* Remove fields column if a new column is added

* Add search source to example plugin.

* Add uiSetting for fields API.

* Update SearchSource to support fields API.

* Improve error handling in search examples plugin.

* Add unit tests for legacy behavior.

* Remove uiSettings feature flag; add fieldsFromSource config.

* Rewrite flatten() based on final API design.

* Update example app based on final API design.

* Update maps app to use legacy fieldsFromSource.

* Update Discover to use legacy fieldsFromSource.

* Rename source filters to field filters.

* Address feedback.

* Update generated docs.

* Update maps functional test.

* Formatting fields column similar to _source

* Moving logic for using search API to updating search source

* Fix small merge error

* Move useSource switch to Discover section of advanced settings

* Do not use fields and source at the same time

* Remove unmapped fields switch

* Add basic support for grouping multifields

* Remove output.txt

* Fix some merge leftovers

* Fix some merge leftovers

* Fix merge errors

* Fix typescript errors and update nested fields logic

* Add a unit test

* Fixing field formats

* Fix multifield selection logic

* Request all fields from source

* Fix eslint

* Fix default columns when switching between _source and fields

* More unit tests

* Update API changes

* Add unit test for discover field details footer

* Remove unused file

* Remove fields formatting from index pattern

* Remove unnecessary check

* Addressing design comments

* Fixing fields column display and renaming it to Document

* Adding more unit tests

* Adding a missing check for useNewFieldsAPI; minor fixes

* Fixing typescript error

* Remove unnecessary console statement

* Add missing prop

* Fixing import order

* Adding functional test to test fields API

* [Functional test] Clean up in after

* Fixing context app

* Addressing PR comments

* Add support for unmapped fields

* Add data migration

* Add toggle unmapped fields logic

* Adding more unit tests

* Some cleanup

* More unit tests

* Fixing failing snapshot

* Add tooltip next to unmapped switch

* Add functional test for the feature

* Fixing a typo in a functional test

* Refetch data when unmapped fields value changes

* Updating mapping

* Support for fields API in search embeddable

* Addressing PR comments

* Fix failing unit test

* Updating the text

Co-authored-by: Luke Elmers <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

* Fixing ES license

Co-authored-by: Luke Elmers <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] Unmapped fields are not shown
6 participants