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] Change default sort handling for index patterns without timefield #54427

Merged
merged 12 commits into from
Jan 24, 2020

Conversation

kertal
Copy link
Member

@kertal kertal commented Jan 10, 2020

Summary

Before this PR, when using index patterns without a timefield, the sorting by _score was added to the state if there was no sort set by user / url. Before multi sort was implemented, this sorting was replaced when switching to an indexpattern with timefield, or when the user adds a sort by field. With the new multisort, switching to another index pattern or selecting another sort field, adds the new field in the sort array in state ( so sorting by _score becomes sorting by _score, newTimefield ).

Solution

The default sort is only used in UI and before sending the Request to ES. It's not added to state. This is only done after user interaction.

You can test this by using our demo data, adding a new index pattern kibana_sample* without a timefield.

Fixes #49050

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [ ] This was checked for cross-browser compatibility, including a check against IE11
- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
- [ ] Documentation was added for features that require explanation or tutorials
- [ ] Unit or functional tests were updated or added to match the most common scenarios
- [ ] This was checked for keyboard-only and screenreader accessibility

For maintainers

- [ ] This was checked for breaking API changes and was labeled appropriately
- [ ] This includes a feature addition or change that requires a release note and was labeled appropriately

- when there's no default search in state (for index pattern without
timefield name). The default sort is set only before the query is sent
 to ES)
@kertal kertal changed the title [Discover]Change default sort handling for index patterns without timefield [Discover] Change default sort handling for index patterns without timefield Jan 10, 2020
@kertal kertal self-assigned this Jan 10, 2020
@kertal kertal added Feature:Discover Discover Application v7.6.0 v8.0.0 Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Jan 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@kertal kertal requested a review from Bargs January 14, 2020 14:22
@kertal kertal marked this pull request as ready for review January 14, 2020 14:22
@kertal kertal requested a review from a team January 14, 2020 14:22
Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

Hmm I see a couple disadvantages to taking _score out of the app state:

  • If the user adds the _score field as a column in the doc table, the UI won't show them that _score is being sorted on.
  • _score and timestamp are both defaults, but they work differently now. If I'm on a non-timebased index pattern and I manually sort on a field, then I switch to a timebased index pattern, I get a multi sort with the first field plus the time field.

Switching index patterns should probably never modify a sort the the user has explicitly added themselves. And I think the UI should always be able to reflect what field is being sorted on even if it is a default.

@kertal
Copy link
Member Author

kertal commented Jan 15, 2020

good points, thx, I will think how to further improve this solution!

@kertal kertal added v7.7.0 and removed v7.6.0 labels Jan 15, 2020
Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

I think this line can be removed since getSort.array no longer takes a defaultOrder
https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js#L523

Otherwise looks good! Nice work 👍

@kertal
Copy link
Member Author

kertal commented Jan 23, 2020

@elasticmachine merge upstream

@kertal
Copy link
Member Author

kertal commented Jan 23, 2020

Thx @Bargs , i've removed the line.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@kertal kertal merged commit ac0953e into elastic:master Jan 24, 2020
kertal added a commit to kertal/kibana that referenced this pull request Jan 24, 2020
…mefield (elastic#54427)

Default sort is no longer in state. There's now a separate function to provide default sort for ES and UI, in case the user didn't actively select a field to sort by
kertal added a commit that referenced this pull request Jan 24, 2020
…mefield (#54427) (#55799)

Default sort is no longer in state. There's now a separate function to provide default sort for ES and UI, in case the user didn't actively select a field to sort by
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discover sorting is inconsistent
4 participants