Percentiles Aggregation Usageedit

Fluent DSL exampleedit

s => s
.Aggregations(a => a
    .Percentiles("commits_outlier", pr => pr
        .Field(p => p.NumberOfCommits)
        .Percents(95, 99, 99.9)
        .Method(m => m
            .HDRHistogram(hdr => hdr
                .NumberOfSignificantValueDigits(3)
            )
        )
        .Script(ss => ss.Inline("doc['numberOfCommits'].value * 1.2").Lang("groovy"))
        .Missing(0)
    )
)

Object Initializer syntax exampleedit

new SearchRequest<Project>
{
    Aggregations = new PercentilesAggregation("commits_outlier", Field<Project>(p => p.NumberOfCommits))
    {
        Percents = new[] { 95, 99, 99.9 },
        Method = new HDRHistogramMethod
        {
            NumberOfSignificantValueDigits = 3
        },
        Script = new InlineScript("doc['numberOfCommits'].value * 1.2") { Lang = "groovy" },
        Missing = 0
    }
}

Example json output.

{
  "aggs": {
    "commits_outlier": {
      "percentiles": {
        "field": "numberOfCommits",
        "percents": [
          95.0,
          99.0,
          99.9
        ],
        "hdr": {
          "number_of_significant_value_digits": 3
        },
        "script": {
          "inline": "doc['numberOfCommits'].value * 1.2",
          "lang": "groovy"
        },
        "missing": 0.0
      }
    }
  }
}

Handling Responsesedit

response.ShouldBeValid();
var commitsOutlier = response.Aggs.Percentiles("commits_outlier");
commitsOutlier.Should().NotBeNull();
commitsOutlier.Items.Should().NotBeNullOrEmpty();
foreach (var item in commitsOutlier.Items)
    item.Value.Should().BeGreaterThan(0);