Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public interface ICompositeAggregationSource
[JsonProperty("missing_bucket")]
bool? MissingBucket { get; set; }


/// <summary>
/// Allows an explicit value to be set when one is missing for the field.
/// </summary>
[Obsolete("Will be removed in Elasticsearch 7.x. Use MissingBucket")]
[JsonProperty("missing")]
object Missing { get; set; }

/// <summary>
/// The name of the source
/// </summary>
Expand Down Expand Up @@ -60,6 +68,10 @@ protected CompositeAggregationSourceBase(string name) =>
/// <inheritdoc />
public bool? MissingBucket { get; set; }

/// <inheritdoc />
[Obsolete("Will be removed in Elasticsearch 7.x. Use MissingBucket")]
public object Missing { get; set; }

/// <inheritdoc />
public SortOrder? Order { get; set; }

Expand Down Expand Up @@ -114,7 +126,8 @@ protected CompositeAggregationSourceDescriptorBase(string name, string sourceTyp

Field ICompositeAggregationSource.Field { get; set; }
bool? ICompositeAggregationSource.MissingBucket { get; set; }

[Obsolete("Will be removed in Elasticsearch 7.x. Use MissingBucket")]
object ICompositeAggregationSource.Missing { get; set; }
string ICompositeAggregationSource.Name { get; set; }
SortOrder? ICompositeAggregationSource.Order { get; set; }
string ICompositeAggregationSource.SourceType => _sourceType;
Expand All @@ -130,6 +143,10 @@ protected CompositeAggregationSourceDescriptorBase(string name, string sourceTyp

/// <inheritdoc cref="ICompositeAggregationSource.MissingBucket" />
public TDescriptor MissingBucket(bool? includeMissing = true) => Assign(a => a.MissingBucket = includeMissing);

/// <inheritdoc cref="ICompositeAggregationSource.Missing" />
[Obsolete("Will be removed in Elasticsearch 7.x. Use MissingBucket")]
public TDescriptor Missing(object missingObject) => Assign(a => a.Missing = missingObject);
}

internal class CompositeAggregationSourceConverter : ReserializeJsonConverter<CompositeAggregationSourceBase, ICompositeAggregationSource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,130 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
}
}

// hide
#pragma warning disable 618
[SkipVersion("<6.4.0", "Missing added to Composite Aggregation Elasticsearch 6.4.0+")]
public class CompositeAggregationMissingUsageTests : ProjectsOnlyAggregationUsageTestBase
{
public CompositeAggregationMissingUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }

protected override object AggregationJson => new
{
my_buckets = new
{
composite = new
{
sources = new object[]
{
new
{
branches = new
{
terms = new
{
field = "branches.keyword",
order = "asc",
missing = "missing_branch"
}
}
},
}
},
aggs = new
{
project_tags = new
{
nested = new { path = "tags" },
aggs = new
{
tags = new { terms = new { field = "tags.name" } }
}
}
}
}
};

protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a
.Composite("my_buckets", date => date
.Sources(s => s
.Terms("branches", t => t
.Field(f => f.Branches.Suffix("keyword"))

.Missing("missing_branch")
.Order(SortOrder.Ascending)
)
)
.Aggregations(childAggs => childAggs
.Nested("project_tags", n => n
.Path(p => p.Tags)
.Aggregations(nestedAggs => nestedAggs
.Terms("tags", avg => avg.Field(p => p.Tags.First().Name))
)
)
)
);

protected override AggregationDictionary InitializerAggs =>
new CompositeAggregation("my_buckets")
{
Sources = new List<ICompositeAggregationSource>
{
new TermsCompositeAggregationSource("branches")
{
Field = Field<Project>(f => f.Branches.Suffix("keyword")),
Missing = "missing_branch",
Order = SortOrder.Ascending
}
},
Aggregations = new NestedAggregation("project_tags")
{
Path = Field<Project>(p => p.Tags),
Aggregations = new TermsAggregation("tags")
{
Field = Field<Project>(p => p.Tags.First().Name)
}
}
};

protected override void ExpectResponse(ISearchResponse<Project> response)
{
response.ShouldBeValid();

var composite = response.Aggregations.Composite("my_buckets");
composite.Should().NotBeNull();
composite.Buckets.Should().NotBeNullOrEmpty();
composite.AfterKey.Should().NotBeNull();

if (TestConfiguration.Instance.InRange(">=6.3.0"))
composite.AfterKey.Should().HaveCount(1).And.ContainKeys("branches");

var i = 0;
var seenMissingBranches = false;
foreach (var item in composite.Buckets)
{
var key = item.Key;
key.Should().NotBeNull();

key.TryGetValue("branches", out string branches).Should().BeTrue("expected to find 'branches' in composite bucket");
branches.Should().NotBeNullOrEmpty();
if (branches == "missing_branch")
{
seenMissingBranches = true;
}

var nested = item.Nested("project_tags");
nested.Should().NotBeNull();

var nestedTerms = nested.Terms("tags");
nestedTerms.Buckets.Count.Should().BeGreaterThan(0);
i++;
}

seenMissingBranches.Should().BeTrue();
}
}
#pragma warning restore 618

//hide
[SkipVersion("<6.3.0", "Date histogram source only supports format starting from Elasticsearch 6.3.0+")]
public class DateFormatCompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
Expand Down