Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

More records in the aggregation query output for script functions, is… #160

Merged
merged 2 commits into from
Aug 22, 2019
Merged

More records in the aggregation query output for script functions, is… #160

merged 2 commits into from
Aug 22, 2019

Conversation

galkk
Copy link
Contributor

@galkk galkk commented Aug 21, 2019

Issue #156
Issue #amazon-archives/sql-jdbc#23

Description of changes:

Changes DSL, generated for aggregation query to have more records returned by default.
Testing:

unit tests,

./gradlew build,

and manual testing via kibana ui

GET /_opendistro/_sql
{
  "query": """
  SELECT date_format(utc_time, 'Y-MM-dd') x, count(*) 
  FROM kibana_sample_data_logs
  WHERE host='www.elastic.co'
  GROUP BY date_format(utc_time, 'Y-MM-dd')
  """
}

to

GET /kibana_sample_data_logs/_search
{
  "from": 0,
  "size": 0,

...

  "_source": {
    "includes": [
      "script",
      "COUNT"
    ],
    "excludes": []
  },
  "stored_fields": "x",
  "script_fields": {
    "x": {
      "script": {
        "source": "def date_format_1282644910 = DateTimeFormatter.ofPattern('Y-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['utc_time'].value.getMillis()));return date_format_1282644910;",
        "lang": "painless"
      },
      "ignore_failure": false
    }
  },
  "aggregations": {
    "x": {
      "terms": {
        "script": {
          "source": "def date_format_1282644910 = DateTimeFormatter.ofPattern('Y-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['utc_time'].value.getMillis()));return date_format_1282644910;",
          "lang": "painless"
        },
        "size": 200, <----------------------------------------------------------------------------------------------------------
        "min_doc_count": 1,
        "shard_min_doc_count": 0,
        "show_term_doc_count_error": false,
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      },
      "aggregations": {
        "COUNT(*)": {
          "value_count": {
            "field": "_index"
          }
        }
      }
    }
  }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@galkk galkk requested review from dai-chen and abbashus August 21, 2019 17:18
Copy link
Member

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Thanks for the code changes!

@galkk galkk requested review from arsen-es and penghuo August 21, 2019 19:58
Copy link
Contributor

@arsen-es arsen-es left a comment

Choose a reason for hiding this comment

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

Please check my reply to the comment added by Chen before you push. Thanks!

@galkk galkk merged commit 545db86 into opendistro-for-elasticsearch:master Aug 22, 2019
@galkk
Copy link
Contributor Author

galkk commented Aug 29, 2019

Fixed #122 as well

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants