Skip to content

Commit 0df154a

Browse files
committed
Document 9.1.8 breaking changes
1 parent f46ba3b commit 0df154a

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

docs/release-notes/breaking-changes.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,124 @@ Breaking changes can impact your Elastic applications, potentially disrupting no
1919
%
2020
% ::::
2121

22+
## 9.1.8 [elasticsearch-net-client-918-breaking-changes]
23+
24+
### Overview
25+
26+
- [1. Improved usability of `CompositeAggregation`](#1-composite-aggregation)
27+
28+
### Breaking changes
29+
30+
#### 1. Improved usability of `CompositeAggregation` [#1-composite-aggregation]
31+
32+
**Impact**: Low.
33+
34+
The type of the `Sources` property has been changed from `ICollection<IDictionary<string, CompositeAggregationSource>>` to `ICollection<KeyValuePair<string, CompositeAggregationSource>>`. This corresponds to the Elasticsearch standard for modeling ordered dictionaries in the REST API.
35+
36+
`CompositeAggregationSource` is now also a container (similar to `Aggregation`, `Query`, etc.). This change improves usability due to specialized code generation. For example, implicit conversion operators from all existing variants (`CompositeTermsAggregation`, `CompositeHistogramAggregation`, etc.) to `CompositeAggregationSource` are now generated.
37+
38+
As a consequence, the object initializer syntax changes as follows:
39+
40+
```csharp
41+
// 9.1.7 and below
42+
43+
var request = new SearchRequest
44+
{
45+
Aggregations = new Dictionary<string, Aggregation>
46+
{
47+
{ "my_composite", new CompositeAggregation
48+
{
49+
Sources =
50+
[
51+
new Dictionary<string, CompositeAggregationSource>
52+
{
53+
{ "my_terms", new CompositeAggregationSource
54+
{
55+
Terms = new CompositeTermsAggregation
56+
{
57+
// ...
58+
}
59+
}}
60+
},
61+
new Dictionary<string, CompositeAggregationSource>
62+
{
63+
{ "my_histo", new CompositeAggregationSource
64+
{
65+
Histogram = new CompositeHistogramAggregation(0.5)
66+
{
67+
// ...
68+
}
69+
}}
70+
}
71+
]
72+
}}
73+
}
74+
};
75+
76+
// 9.1.8 and above
77+
78+
var request = new SearchRequest
79+
{
80+
Aggregations = new Dictionary<string, Aggregation>
81+
{
82+
{ "my_composite", new CompositeAggregation
83+
{
84+
Sources =
85+
[
86+
new KeyValuePair<string, CompositeAggregationSource>(
87+
"my_terms",
88+
new CompositeTermsAggregation // <-- implicit conversion
89+
{
90+
// ...
91+
}
92+
),
93+
new KeyValuePair<string, CompositeAggregationSource>(
94+
"my_histo",
95+
new CompositeHistogramAggregation(0.5) // <-- implicit conversion
96+
{
97+
// ...
98+
}
99+
)
100+
]
101+
}}
102+
}
103+
};
104+
```
105+
106+
In addition, this change allows optimized Fluent syntax to be generated, which ultimately avoids a previously existing ambiguity:
107+
108+
```csharp
109+
// 9.1.7 and below
110+
111+
var descriptor = new SearchRequestDescriptor()
112+
.Aggregations(aggs => aggs
113+
.Add("my_composize", agg => agg
114+
.Composite(composite => composite
115+
.Sources( // <-- 'params' overload
116+
x => x.Add("my_terms", x => x.Terms(/* ... */)), // dictionary 1 with a single entry
117+
x => x.Add("my_histo", x => x.Histogram(/* ... */)) // dictionary 2 with a single entry
118+
)
119+
)
120+
)
121+
);
122+
123+
// 9.1.8 and above
124+
125+
var descriptor = new SearchRequestDescriptor()
126+
.Aggregations(aggs => aggs
127+
.Add("my_composize", agg => agg
128+
.Composite(composite => composite
129+
.Sources(sources => sources
130+
.Add("my_terms", x => x.Terms(/* ... */))
131+
.Add("my_histo", x => x.Histogram(/* ... */))
132+
)
133+
)
134+
)
135+
);
136+
```
137+
138+
The old syntax was tricky because the 9.1.8 example also compiled successfully, but the `.Add` referred to the first dictionary both times. This ultimately resulted in a list with only one dictionary, which had multiple entries, and thus an invalid request.
139+
22140
## 9.1.1 [elasticsearch-net-client-911-breaking-changes]
23141

24142
### Overview

0 commit comments

Comments
 (0)