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

[Lens] Create a filter with field:value when last value metric is used on a datatable #160509

Merged
merged 4 commits into from
Jun 29, 2023

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Jun 26, 2023

Fixes #152883

The task says this is the behavior that we want for datatable, but with the way data plugin interacts with Lens, it's actually impossible to modify only for datatable. In my opinion that's an improvement though, we probably want the same behavior for all supported visualization (so also metric).

Scenarios to test:

Screenshot 2023-06-27 at 09 10 35

1,2,3 returns the price:${value} filter
4. returns price:exists filter
5. returns category.keyword:${value} coming from filter by
6. OR filter for array values
Screenshot 2023-06-28 at 16 31 43

@mbondyra mbondyra added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens release_note:feature Makes this part of the condensed release notes v8.10.0 labels Jun 26, 2023
@mbondyra mbondyra marked this pull request as ready for review June 26, 2023 14:07
@mbondyra mbondyra requested review from a team as code owners June 26, 2023 14:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations @elastic/kibana-visualizations-external (Team:Visualizations)

@mbondyra mbondyra added release_note:enhancement and removed release_note:feature Makes this part of the condensed release notes labels Jun 27, 2023
@mbondyra mbondyra marked this pull request as draft June 28, 2023 14:20
@mbondyra mbondyra marked this pull request as ready for review June 28, 2023 14:43
Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

I tested all the cases you suggested and everything worked well.

I did find a confusing scenario, but I'm not sure if there's anything we can do.

When you're dealing with an array value but you have "Show array values" turned off (using top_metrics agg instead of top_hits), the filter that is created excludes all the documents in the time range, making the metric go blank (ignore the terrible formatting you see in the video, I created an issue for that: #160815).

Screen.Recording.2023-06-28.at.2.41.38.PM.mov

This is definitely because of elastic/elasticsearch#82281 (original issue in Lens #102956).

I did some experiments on top_metrics and, given an array of numbers, top_metrics returns a single number that seems to be somehow computed from the numbers in the array, but through no predictable calculation I could figure out.

DELETE abc

POST abc/_doc
{
  "arr": [10, 50],
  "timestamp": "2020-02-02T00:00:00.000Z"
}

GET abc/_search
{
  "size": 0,
  "aggs": {
    "a": {
      "top_metrics": {
        "metrics": {"field": "arr"},
        "sort": {"timestamp": "desc"}   
      }
    }
  }
}

Result:

"aggregations": {
    "a": {
      "top": [
        {
          "sort": [
            "2020-02-02T00:00:00.000Z"
          ],
          "metrics": {
            "arr": 30
          }
        }
      ]
    }

So in this scenario the filter would get created as arr : 30 which doesn't match any docs. (Also, why 30? Docs say "A top_metric aggregation on array values may return inconsistent results.")

Anyway, not caused in any way by your PR, but perhaps something we could connect with ES about as a follow-up.

Copy link
Contributor Author

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Thanks @drewdaemon for the thorough review! So the mentioned problem happens because of precision? Eg day_of_week_i doesn't have this effect and creates a correct filter. I am wondering if we should just block key:value filter for last values when value is of type number and is not integer (so has a fraction). Not sure though. @stratoula WDYT?

@stratoula
Copy link
Contributor

@mbondyra I am trying to decide which option is going to cause less confusion. I tend to believe that we should keep it as it is on your PR. I feel that if numeric fields work differently it will cause more confusion.
It makes sense to talk to ES about it. I feel that if it creates confusion we can explain easily why it happens.

@mbondyra
Copy link
Contributor Author

Scratch that, it's because of the last value actually being an array, not because of the precision so it wouldn't help anyway. Yeah, it's probably on elasticsearch, let's talk during the sync.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

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

id before after diff
data 406.5KB 406.9KB +385.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 413 417 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 492 496 +4
total +6

History

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

@mbondyra mbondyra merged commit d9b3a53 into elastic:main Jun 29, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 29, 2023
@mbondyra mbondyra deleted the lens/filters_last_value branch June 29, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Create a filter with field:value when last value metric is used on a datatable
6 participants