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

[Maps] Introduce bucket-selector or any post-aggregation filtering(like having in sql) into region map elastic-search/kibana #63401

Closed
sleshJdev opened this issue Apr 13, 2020 · 17 comments
Assignees
Labels
enhancement New value added to drive a business result Feature:Maps impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas

Comments

@sleshJdev
Copy link

I have tabular data by districts and days. Each row contains diff between the current and previous days, i.e. relative value.

 district |     day    | metric 
----------+------------+--------
 D1       | 2020-04-12 | -11     
 D1       | 2020-04-13 |  40
 D2       | 2020-04-13 |  20     
 D1       | 2020-04-14 |  11         
 D1       | 2020-04-15 | -50

I need to visualize this data on Kibana's region map.

So, the metric is grouped by district and summarized. Here is the ElasticSearch query generated by Kibana:

{"aggs": {
    "2": {
      "terms": {
        "field": "district",
        "size": 300,
        "order": {
          "1": "desc"
        }},
      "aggs": {
        "1": {
          "sum": {
            "field": "metric"
          }}}}},
  "query": {
    "bool": {
      "must": [{
          "range": {
            "@timestamp": {
              "format": "strict_date_optional_time",
              "gte": "2020-04-12T00:00:00.0Z",
              "lte": "2020-04-16T00:00:00.0Z"
            }}}]}}}  

Depending on the selected data rage the result will vary. For example, this query selects all data (see @timestamp filter) and metric values for districts D1 and D2 will be -10 and 20. If I'll change the filter to select data for 12-13 April it will be -11 + 40 = 29 for D1 and 20 for D2.

In Kibana I need to filter out buckets with negative sum(metric) value and show districts only with a positive sum value. I couldn't find any working solution. I've tried

  • Kibana's JSON input + Bucket Selector
    Aggregation

    Visual
  • Kibana's Vega Graphs, but it seems that it doesn't support region maps.
    I'd like to avoid it as it's quite complicated.
  • Build a new index based on the existing ones, but it's not possible as
    a result depends on a date range filter, so I cannot pre-calculate metrics and filter out negatives because I don't know what date range is in advanced

Nothing of this worked for me. I was able to compose a working Elastic Search query that does exactly what I want, but I don't know how to visualize it using the region map:

{"aggs": {
    "2": {
      "terms": {
        "field": "district",
        "size": 300,
        "order": {
          "1": "desc"
        }},
      "aggs": {
        "1": {
          "sum": {
            "field": "metric"
          },
          "1_bucket_selector": { -- here is main part, how get it in region map?
            "bucket_selector": {
              "buckets_path": {
                "metricSum": "1"
              },
              "script": "params.metricSum > 0"
            }}}}}}}

So, any workaround to achieve what I want?

Here is a related topic on Kibana forum

ELK stack version is 7.0

@rashmivkulkarni rashmivkulkarni added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Apr 13, 2020
@elasticmachine
Copy link
Contributor

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

@nreese nreese added enhancement New value added to drive a business result [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation labels Apr 13, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-gis (Team:Geo)

@nreese nreese removed the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Apr 13, 2020
@sleshJdev
Copy link
Author

Guys, how you feel about introducing sql-having-like functionality into Maps? Currently, it only supports filtering by filter from a document, but would be useful to be able to filter out by aggregated properties.

@sleshJdev
Copy link
Author

I could try to prepare PR for that

@nreese
Copy link
Contributor

nreese commented Jun 2, 2020

how you feel about introducing sql-having-like functionality into Maps?

What are you proposing? Any SQL functionality would have to use elastic SQL plugin. Here is a link to an open issue for supporting SQL in Maps if you would like to describe your use case there.

@sleshJdev
Copy link
Author

As I described in the issue intro, I need some wat to do additional filtering for aggregated data when I configure Map. For example, I want to filter out metric value by some criteria(how sql-having behaves). Now I can only filter the documents, but not aggregated data.

@sleshJdev
Copy link
Author

Does it make sense?

@nreese
Copy link
Contributor

nreese commented Jun 3, 2020

@sleshJdev
Copy link
Author

sleshJdev commented Jun 14, 2020

Hmm, it's a map-reduce approach and it could potentially work for sure. But it could involve too many changes to re-work existing code to work with a new API. What about search-aggregations-pipeline-bucket-selector-aggregation? It seems to be much easier for integration. What do you think?

@nreese
Copy link
Contributor

nreese commented Jun 15, 2020

That would be useful to expose as well.

@sleshJdev
Copy link
Author

Cool, I'll try to prepare PR. No ETA, sorry

@thomasneirynck thomasneirynck changed the title Introduce bucket-selector or any post-aggregation filtering(like having in sql) into region map elastic-search/kibana [Maps] Introduce bucket-selector or any post-aggregation filtering(like having in sql) into region map elastic-search/kibana Jul 14, 2020
@thomasneirynck
Copy link
Contributor

related #55520

@thomasneirynck
Copy link
Contributor

Most map-related enhancement will go to the Maps app, and it is unlikely any improvements will be added to the region-map visualization. This is a useful ER though. To improve visibility, I modified the title of this ticket to reflect that this should target the Maps-app.

@odmby
Copy link

odmby commented Sep 30, 2020

this is useful not only for maps, but for any visualization to have "post result" filtering on the calculated values. ("HAVING" in SQL)

@wylieconlon
Copy link
Contributor

It seems like most users who are requesting this feature are asking for filtering based on the aggregated number, so I've proposed a few simplifications to Lens. We haven't yet discussed this, but you may find it useful in thinking about the problem: #86190

@jb1b84 jb1b84 added Feature:Maps Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas labels Nov 3, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@jb1b84 jb1b84 removed the [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation label Nov 3, 2022
@nreese nreese added loe:large Large Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. labels Mar 9, 2023
@nreese
Copy link
Contributor

nreese commented Apr 22, 2023

Closed by #154983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Maps impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:large Large Level of Effort Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas
Projects
None yet
Development

No branches or pull requests

8 participants