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

[context view] Use _doc for tie-breaking instead of _uid #12096

Merged
merged 4 commits into from
Jun 8, 2017

Conversation

weltenwort
Copy link
Member

@weltenwort weltenwort commented May 31, 2017

Using fields with docvalues (like _doc) for tie-breaking yields
significantly better performance than using _uid, which lacks
docvalues at the moment. The downside is that sorting by _doc by
default is not stable under all conditions, but better than no
tie-breaking at all.

The new setting context:tieBreakingFields enables the user to
customize the list of fields Kibana attempts to use for tie-breaking.
The first field from that list, that is sortable in the current index
pattern, will be used. It defaults to _doc, which should change to
_seq_no from version 6.0 on.

Summary: To avoid filling up Elasticsearch's fielddata cache by
sorting on the _uid field in the context view, the field _doc is now
used as a tiebreaker by default. The field to be used can now be
configured using the context:tieBreakingFields advanced setting.

fixes #11925

@weltenwort weltenwort self-assigned this May 31, 2017
@weltenwort weltenwort force-pushed the fix/context-uid-fielddata branch from 5231c19 to 022f971 Compare June 2, 2017 12:57
@weltenwort weltenwort changed the title Use _doc for tie-breaking instead of _uid [context view] Use _doc for tie-breaking instead of _uid Jun 2, 2017
@weltenwort weltenwort requested review from Bargs and lukasolson June 2, 2017 14:27
@weltenwort weltenwort added review and removed WIP Work in progress labels Jun 2, 2017
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.

Can you also update the docs with the new setting?

`context:step`:: Specifies the number to increment or decrement the context size by when using the buttons in the context view. The default value is 5.

},
'context:tieBreakerFields': {
value: ['_doc'],
description: 'A list of fields to use for tie-breaking between documents ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add that it's a comma delimited list of fields? Even I had to stop for a moment to figure out how to enter multiple fields in the input.

function getFirstSortableField(indexPattern, fieldNames) {
const sortableFields = fieldNames.filter((fieldName) => (
META_FIELD_NAMES.includes(fieldName)
|| (indexPattern.fields.byName[fieldName] || { sortable: false }).sortable
Copy link
Contributor

Choose a reason for hiding this comment

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

If none of the configured fields match a meta field or index pattern field, context will throw a fatal error (as a result of sending a bad request to ES). Same thing happens if the field exists, but is not sortable. We should handle this more elegantly so the user knows how to fix the problem.

screen shot 2017-06-02 at 11 46 07 am

Copy link
Member Author

Choose a reason for hiding this comment

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

The fatal error being shown is a consequence of #12124, which I'm trying to fix as well right now. This has proven to be more difficult than expected, but as soon as I have worked around the error handling memory leaks in courier I will handle these more gracefully.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case we're sending an invalid query to elasticsearch though, which I don't think we should do in the first place. The sort portion of the query looks like this:

  "sort": [
    {
      "@timestamp": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    },
    {
      "undefined": {
        "order": "asc",
        "unmapped_type": "boolean"
      }
    }
  ],

Instead, what if we fail early if there are no valid tiebreaker fields and notify the user with a message saying they need to set a valid tiebreaker field?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're absolutely right... I had my head in the error handling code so deep I didn't see that avoiding the error is the obvious solution. 😊

@spalger spalger added the v5.6.0 label Jun 7, 2017
Using fields with docvalues (like `_doc`) for tie-breaking yields
significantly better performance than using `_uid`, which lacks
docvalues at the moment. The downside is that sorting by `_doc` by
default is not stable under all conditions, but better than no
tie-breaking at all.

The new setting `context:tieBreakingFields` enables the user to
customize the list of fields Kibana attempts to use for tie-breaking.
The first field from that list, that is sortable in the current index
pattern, will be used. It defaults to `_doc`, which should change to
`_seq_no` from version 6.0 on.
In addition to just showing a notification, errors that occur while
loading documents from the database will be stored as part of the
`loadingStatus` along with a reason code (if known). This is used to
display more nuanced and helpful error messages to the user.

The first such error message indicates a missing or invalid tiebreaker
field required for sorting the context.
@weltenwort weltenwort force-pushed the fix/context-uid-fielddata branch from 022f971 to a92628e Compare June 7, 2017 15:00
@weltenwort
Copy link
Member Author

@Bargs @lukasolson I think this is ready for another view. The prior review comments should have been addressed:

  • Avoid hitting ES when there is no intersection between the configured tiebreaker fields and the sortable fields in the index pattern. Display a helpful message instead.
  • Add new config option to the advanced settings documentation.
  • Clarify comma-separation of config values.

@Bargs
Copy link
Contributor

Bargs commented Jun 7, 2017

Looks great!

weltenwort added a commit to weltenwort/kibana that referenced this pull request Jun 8, 2017
Using fields with docvalues (like `_doc`) for tie-breaking yields
significantly better performance than using `_uid`, which lacks
docvalues at the moment. The downside is that sorting by `_doc` by
default is not stable under all conditions, but better than no
tie-breaking at all.

The new setting `context:tieBreakingFields` enables the user to
customize the list of fields Kibana attempts to use for tie-breaking.
The first field from that list, that is sortable in the current index
pattern, will be used. It defaults to `_doc`, which should change to
`_seq_no` from version 6.0 on.

In addition to just showing a notification, errors that occur while
loading documents from the database will be stored as part of the
`loadingStatus` along with a reason code (if known). This is used to
display more nuanced and helpful error messages to the user.

The first such error message indicates a missing or invalid tiebreaker
field required for sorting the context.
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.

[context view] using the _uid field as a tiebreaker consumes a lot of fielddata memory
4 participants