Skip to content

Conversation

@paulness
Copy link

@paulness paulness commented Aug 23, 2022

A very minor feature enhancement. ElasticSearch supports an inline script property on the VariableWidthHistogram. This PR makes this supported by the high level NEST client.

This is already supported by the MultiTermsAggregation

--
There is a useful use-case for this enhancement which is to bucket ranges on the log scale on the VariableWidthHistogram. This results in a more even distribution.

Example of use case

GET arc-37-5/_search
{
	"aggs": {
		"prices": {
			"variable_width_histogram": {
				"field": "lot.sold_prices_usd",
				"script": {
				  "source": "Math.log10(_value)"
				},
				"buckets": 300
			}
		}
	},
	"size": 0
}
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "prices" : {
      "buckets" : [
        {
          "min" : 0.0,
          "key" : 0.20126268733718639,
          "max" : 0.6989700043360189,
          "doc_count" : 585
        },
        {
          "min" : 0.7781512503836436,
          "key" : 2.036468418035862,
          "max" : 2.294415862797104,
          "doc_count" : 11561
        },
        {
          "min" : 2.294415862797104,
          "key" : 3.4601699053739163,
          "max" : 4.910529536362189,
          "doc_count" : 2103060
        },
        {
          "min" : 4.910529536362189,
          "key" : 5.365584337340739,
          "max" : 7.101131689337512,
          "doc_count" : 82957
        },
        {
          "min" : 7.101131689337512,
          "key" : 7.3633284959971546,
          "max" : 8.04433197055116,
          "doc_count" : 360
        }
      ]
    }
  }
}

The log values can then be converted back to the original values afterwards.

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@stevejgordon
Copy link
Contributor

@elasticmachine test this please

Copy link
Contributor

@stevejgordon stevejgordon left a comment

Choose a reason for hiding this comment

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

LGTM!

@stevejgordon
Copy link
Contributor

Thanks for this contribution, @paulness. Apologies for the delay in getting to it. I have been focused on 8.x work.

@stevejgordon
Copy link
Contributor

clients-ci failure is unrelated

@stevejgordon stevejgordon added Feature 7.x Relates to a 7.x client version labels Oct 19, 2022
@stevejgordon stevejgordon merged commit 6888a2c into elastic:7.17 Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x Relates to a 7.x client version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants