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] "Top Values" allows setting missing values switch for numeric fields #102640

Closed
maihde opened this issue Jun 18, 2021 · 6 comments · Fixed by #102865
Closed

[Lens] "Top Values" allows setting missing values switch for numeric fields #102640

maihde opened this issue Jun 18, 2021 · 6 comments · Fixed by #102865
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@maihde
Copy link
Contributor

maihde commented Jun 18, 2021

Kibana version: master @ b5f0bc9

Elasticsearch version: 8.0.0 snapshot

Original install method (e.g. download page, yum, from source, etc.): Source

Describe the bug:

Addition:
Part of this is fixed already - #102640 (comment) is the missing part

Legacy aggregation based visualizations didn't allow "Show missing values" to be selected with "Terms" aggregations against numeric fields. The bug is that Lens attempts to implement similar behavior by preventing "Top values" from being used at all by showing an error that says "To use this function, select a different field.". There are two bugs:

  1. A numeric field should be allowed with "Top values" without any error prompt
  2. By simply toggling the drop down or not using the "Drop field" you can get "Top values" to work with a numeric field without error.

Describe the feature:

Support missing values in Lens and Terms-based aggregation visualizations on numeric fields.

Steps to reproduce:

  1. Insert Data
POST test_data/_doc/
{
  "timestamp": "2021-06-17T02:03:04Z",
  "a_string_field": "A",
  "a_number_field": 0

}
POST test_data/_doc/
{
  "timestamp": "2021-06-17T02:03:04Z",
  "a_string_field": "B"
}
  1. Create index pattern
  2. Create Lens visualization on test_data with horizontal axis timestamp and vertical axis Count verify 3 records are shown.
  3. Click on "Drop a field or click to add" on Break down by
  4. Select "Top values" then select a_number_field. Observe that two records are shown with values of 0 and 1 in legend.
  5. Expand "Advanced" and enable "Include documents without this field". Observe that only 2 records are shown.
  6. Return to top level Lens configuration and clear "Break down by" fields.
  7. Drag a_number_field onto Break down by and then click it
  8. Click on "Top values" observe that error says "To use this function, select a different field."
  9. Click the drop-down box and select a_string_field.keyword and repeat and select a_number_field. Observe that "Top values" configuration is now available.

Expected behavior:

Step 7 - three records are shown
Step 10 - no error message is shown
Step 5 & 11 - behavior is inconsistent about showing error message, but once the error message is removed for numeric fields this will become a non-issue.

Any additional context:

My suspicion is because doing this type of aggregation:

POST test_data/_search?size=0
{
    "aggs": {
      "2": {
        "terms": {
          "field":"a_number_field",
          "order":{"_count":"desc"},
          "size":5,
          "missing": "Missing"
        }
      }
    }
}

Fails with

        "reason" : {
          "type" : "number_format_exception",
          "reason" : "For input string: \"Missing\""
        }

But an alternative is that when the "Show missing values is enabled" to simply add a 'filter' aggregation:

POST test_data/_search?size=0
{
  "aggs": {
    "2": {
      "terms": {
        "field":"a_number_field",
        "order":{"_count":"desc"},
        "size":5
      }
    },
    "missing": {
      "filter": {
        "bool": {
          "must_not": { "exists": { "field": "a_number_field" } }
        }
      }
    }
  }
}

With this implementation, missing values can be used for both string and numeric Terms/Top values aggregations.

@maihde maihde added the bug Fixes for quality problems that affect the customer experience label Jun 18, 2021
@botelastic botelastic bot added the needs-team Issues missing a team label label Jun 18, 2021
@azasypkin azasypkin added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Jun 21, 2021
@elasticmachine
Copy link
Contributor

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

@botelastic botelastic bot removed the needs-team Issues missing a team label label Jun 21, 2021
@flash1293
Copy link
Contributor

flash1293 commented Jun 21, 2021

The bug is that Lens attempts to implement similar behavior by preventing "Top values" from being used at all by showing an error that says "To use this function, select a different field."

Top values should work with number fields - it's not related to the missing bucket issues.

@dej611 Does #102384 fix this? Sounds very similar.,

@dej611
Copy link
Contributor

dej611 commented Jun 21, 2021

Sounds similar to me as well.

@flash1293
Copy link
Contributor

The fact missing can be set for number fields in Lens is a real bug though - I will keep the issue open to track fixing this part.

@flash1293 flash1293 changed the title Bug: Lens "Top Values" has inconsistent behavior with numeric fields Feat: Support missing values in numeric "Top Values" and Terms aggregations Bug: Lens "Top Values" allows setting missing values switch Jun 21, 2021
@maihde
Copy link
Contributor Author

maihde commented Jun 21, 2021

@flash1293 my hope is that the fix for allowing setting "missing" values is accomplished by altering the behavior such that missing values can be shown for numeric fields (as shown above) instead of blocking the selection of "missing". I understand this becomes more of a feature request, but our users frequently complain about the inability to use "missing" in conjunction with numeric fields.

@flash1293 flash1293 changed the title Bug: Lens "Top Values" allows setting missing values switch [Lens] "Top Values" allows setting missing values switch for numeric fields Jun 22, 2021
@flash1293
Copy link
Contributor

flash1293 commented Jun 22, 2021

@maihde There are some technical challenges in doing this - I think it's worth a separate issue. However, there should be an easy workaround - extend your mapping and index the number as a keyword as well:

{
  "mappings": {
    "properties": {
      "field1": {
        "type": "double",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

On field1.keyword you can use the missing option and it will work just fine.

Note: You won't be able to format the numbers this way.

The requirement for missing option on numeric fields (without mapping tricks) is absolutely justified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants