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

Composite aggregation ignores value script in terms source #53135

Closed
hendrikmuhs opened this issue Mar 4, 2020 · 5 comments
Closed

Composite aggregation ignores value script in terms source #53135

hendrikmuhs opened this issue Mar 4, 2020 · 5 comments
Labels
>bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@hendrikmuhs
Copy link

hendrikmuhs commented Mar 4, 2020

Using a terms source in a composite aggregation is documented to fully support scripts in the same way as terms aggregation:

The terms value source is equivalent to a simple terms aggregation. The values are extracted from a field or a script exactly like the terms aggregation.

However, value script does not work as expected but is silently ignored.

Workaround

Instead of using _value use doc[{field_name}]

Reproduction

The described behavior can be reproduced using the kibana sample data logs:

GET kibana_sample_data_logs/_search
{
  "size": 0,
  "aggs": {
    "my_composite_agg": {
      "composite": {
        "sources": [
          {
            "agent": {
              "terms": {
                "field": "agent.keyword",
                "script": {
                  "source": "'agent: ' + _value"}
              }
            }
          }
        ]
      }
    }
  }
}

returns e.g.

      "buckets" : [
        {
          "key" : {
            "agent" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
          },
          "doc_count" : 4010
        },

while the expected output is:

      "buckets" : [
        {
          "key" : {
            "agent" : "agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
          },
          "doc_count" : 4010
        },

I am not sure if this is really a bug or a technical limitation. If its a limitation the documentation should not claim full support and the search request using a value script should error.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

@hendrikmuhs
Copy link
Author

I debugged this to learn a bit about the implementation of aggs. #53232 contains what I found out and also has a quick-fix for it.

@rjernst rjernst added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 4, 2020
@bczifra
Copy link
Member

bczifra commented May 12, 2020

@hendrikmuhs I've run into field+script issues before, such as #43390. Pulling the entire content into the script will work reliably:

GET kibana_sample_data_logs/_search
{
  "size": 0,
  "aggs": {
    "my_composite_agg": {
      "composite": {
        "sources": [
          {
            "agent": {
              "terms": {
                "script": {
                  "source": "'agent: ' + doc['agent.keyword']"}
              }
            }
          }
        ]
      }
    }
  }
}

@hendrikmuhs
Copy link
Author

@bczifra Thanks. yes using doc works, I should have mentioned this for readers of the issue. I will update the entry post.

@wchaparro
Copy link
Member

closing as not planned.

@wchaparro wchaparro closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants