elasticsearch-net icon indicating copy to clipboard operation
elasticsearch-net copied to clipboard

Add script property to variable width histogram

Open paulness opened this issue 1 year ago • 1 comments

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 https://github.com/elastic/elasticsearch-net/blob/96f36d0bbd47aefd781502cf0373df81ad686602/src/Nest/Aggregations/Bucket/MultiTerms/MultiTermsAggregation.cs#L54

-- 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.

paulness avatar Aug 23 '22 20:08 paulness

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?

elasticmachine avatar Aug 23 '22 20:08 elasticmachine

@elasticmachine test this please

stevejgordon avatar Oct 19 '22 09:10 stevejgordon

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

stevejgordon avatar Oct 19 '22 09:10 stevejgordon

clients-ci failure is unrelated

stevejgordon avatar Oct 19 '22 09:10 stevejgordon