Skip to content

Commit 323e917

Browse files
committed
Document 9.1.8 breaking changes
1 parent f46ba3b commit 323e917

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

docs/release-notes/breaking-changes.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,131 @@ 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 <1>
89+
{
90+
// ...
91+
}
92+
),
93+
new KeyValuePair<string, CompositeAggregationSource>(
94+
"my_histo",
95+
new CompositeHistogramAggregation(0.5) <2>
96+
{
97+
// ...
98+
}
99+
)
100+
]
101+
}}
102+
}
103+
};
104+
```
105+
106+
1. Implicit conversion from `CompositeTermsAggregation` to `CompositeAggregationSource`.
107+
2. Implicit conversion from `CompositeHistogramAggregation` to `CompositeAggregationSource`.
108+
109+
In addition, this change allows optimized Fluent syntax to be generated, which ultimately avoids a previously existing ambiguity:
110+
111+
```csharp
112+
// 9.1.7 and below
113+
114+
var descriptor = new SearchRequestDescriptor()
115+
.Aggregations(aggs => aggs
116+
.Add("my_composize", agg => agg
117+
.Composite(composite => composite
118+
.Sources( <1>
119+
x => x.Add("my_terms", x => x.Terms(/* ... */)), <2>
120+
x => x.Add("my_histo", x => x.Histogram(/* ... */)) <3>
121+
)
122+
)
123+
)
124+
);
125+
126+
// 9.1.8 and above
127+
128+
var descriptor = new SearchRequestDescriptor()
129+
.Aggregations(aggs => aggs
130+
.Add("my_composize", agg => agg
131+
.Composite(composite => composite
132+
.Sources(sources => sources
133+
.Add("my_terms", x => x.Terms(/* ... */))
134+
.Add("my_histo", x => x.Histogram(/* ... */))
135+
)
136+
)
137+
)
138+
);
139+
```
140+
141+
1. This is the `params` overload that initializes the `Sources` collection with multiple entries.
142+
2. Add dictionary item 1 that contains a single `Terms` aggregation entry.
143+
3. Add dictionary item 2 that contains a single `Histogram` aggregation entry.
144+
145+
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.
146+
22147
## 9.1.1 [elasticsearch-net-client-911-breaking-changes]
23148

24149
### Overview

0 commit comments

Comments
 (0)