Skip to content

Commit aae7aa7

Browse files
Responding to latest spec fixes (#6490) (#6491)
Co-authored-by: Steve Gordon <[email protected]>
1 parent 8e1592e commit aae7aa7

26 files changed

+766
-427
lines changed

src/Elastic.Clients.Elasticsearch/Common/Infer/Field/Field.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Elastic.Clients.Elasticsearch;
1414

1515
[JsonConverter(typeof(FieldConverter))]
1616
[DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")]
17-
public sealed class Field : IEquatable<Field>, IUrlParameter
17+
public sealed class Field : IEquatable<Field>, IUrlParameter, IDictionaryKey
1818
{
1919
private readonly object _comparisonValue;
2020
private readonly Type _type;
@@ -95,15 +95,26 @@ public bool Equals(Field other) => _type != null
9595
? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue)
9696
: other != null && _comparisonValue.Equals(other._comparisonValue);
9797

98-
string IUrlParameter.GetString(ITransportConfiguration? settings)
98+
string IUrlParameter.GetString(ITransportConfiguration settings)
9999
{
100-
if (!(settings is IElasticsearchClientSettings ElasticsearchSettings))
100+
if (settings is not IElasticsearchClientSettings elasticsearchSettings)
101101
{
102102
throw new ArgumentNullException(nameof(settings),
103103
$"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided");
104104
}
105105

106-
return ElasticsearchSettings.Inferrer.Field(this);
106+
return GetStringCore(elasticsearchSettings);
107+
}
108+
109+
private string GetStringCore(IElasticsearchClientSettings settings)
110+
{
111+
if (settings is null)
112+
{
113+
throw new ArgumentNullException(nameof(settings),
114+
$"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided");
115+
}
116+
117+
return settings.Inferrer.Field(this);
107118
}
108119

109120
public override string ToString() => DebugDisplay;
@@ -172,6 +183,8 @@ public override bool Equals(object obj)
172183
}
173184
}
174185

186+
string IDictionaryKey.Key(IElasticsearchClientSettings settings) => GetStringCore(settings);
187+
175188
public static bool operator ==(Field x, Field y) => Equals(x, y);
176189

177190
public static bool operator !=(Field x, Field y) => !Equals(x, y);

src/Elastic.Clients.Elasticsearch/Serialization/UnionConverter.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public override JsonConverter CreateConverter(
6161
}
6262

6363
private class DerivedUnionConverterInner<TType, TItem1, TItem2> : JsonConverter<TType>
64+
where TType : Union<TItem1, TItem2>
6465
{
6566
public override TType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
6667
{
@@ -72,7 +73,7 @@ private class DerivedUnionConverterInner<TType, TItem1, TItem2> : JsonConverter<
7273
{
7374
var itemOne = JsonSerializer.Deserialize<TItem1>(ref readerCopy, options);
7475

75-
if (itemOne is TItem1)
76+
if (itemOne is not null)
7677
{
7778
reader = readerCopy;
7879
return (TType)Activator.CreateInstance(typeof(TType), itemOne);
@@ -87,7 +88,7 @@ private class DerivedUnionConverterInner<TType, TItem1, TItem2> : JsonConverter<
8788
{
8889
var itemTwo = JsonSerializer.Deserialize<TItem2>(ref reader, options);
8990

90-
if (itemTwo is TItem2)
91+
if (itemTwo is not null)
9192
{
9293
return (TType)Activator.CreateInstance(typeof(TType), itemTwo);
9394
}
@@ -109,20 +110,19 @@ public override void Write(Utf8JsonWriter writer, TType value,
109110
return;
110111
}
111112

112-
//if (value.Item1 is not null)
113-
//{
114-
// JsonSerializer.Serialize(writer, value.Item1, value.Item1.GetType(), options);
115-
// return;
116-
//}
113+
if (value.Item1 is not null)
114+
{
115+
JsonSerializer.Serialize(writer, value.Item1, value.Item1.GetType(), options);
116+
return;
117+
}
117118

118-
//if (value.Item2 is not null)
119-
//{
120-
// JsonSerializer.Serialize(writer, value.Item2, value.Item2.GetType(), options);
121-
// return;
122-
//}
119+
if (value.Item2 is not null)
120+
{
121+
JsonSerializer.Serialize(writer, value.Item2, value.Item2.GetType(), options);
122+
return;
123+
}
123124

124-
throw new JsonException("TODO");
125-
//throw new JsonException("Invalid union type.");
125+
throw new JsonException("Invalid union type.");
126126
}
127127
}
128128

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.Aggregations;
6+
7+
public partial class AggregateOrder
8+
{
9+
public static AggregateOrder KeyDescending => new(new System.Collections.Generic.Dictionary<Field, SortOrder>
10+
{
11+
{ "_key", SortOrder.Desc }
12+
});
13+
14+
public static AggregateOrder KeyAscending => new(new System.Collections.Generic.Dictionary<Field, SortOrder>
15+
{
16+
{ "_key", SortOrder.Asc }
17+
});
18+
19+
public static AggregateOrder CountDescending => new(new System.Collections.Generic.Dictionary<Field, SortOrder>
20+
{
21+
{ "_count", SortOrder.Desc }
22+
});
23+
24+
public static AggregateOrder CountAscending => new(new System.Collections.Generic.Dictionary<Field, SortOrder>
25+
{
26+
{ "_count", SortOrder.Asc }
27+
});
28+
}

src/Elastic.Clients.Elasticsearch/Types/Aggregations/HistogramOrder.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Transport;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq.Expressions;
22+
using System.Text.Json;
23+
using System.Text.Json.Serialization;
24+
25+
#nullable restore
26+
namespace Elastic.Clients.Elasticsearch.Aggregations
27+
{
28+
public partial class AggregateOrder : Union<Dictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.SortOrder>?, IReadOnlyCollection<Dictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.SortOrder>>?>
29+
{
30+
public AggregateOrder(Dictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.SortOrder>? item) : base(item)
31+
{
32+
}
33+
34+
public AggregateOrder(IReadOnlyCollection<Dictionary<Elastic.Clients.Elasticsearch.Field, Elastic.Clients.Elasticsearch.SortOrder>>? item) : base(item)
35+
{
36+
}
37+
}
38+
}

src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/DateHistogramAggregation.g.cs

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override DateHistogramAggregation Read(ref Utf8JsonReader reader, Type ty
118118

119119
if (reader.ValueTextEquals("order"))
120120
{
121-
var value = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder?>(ref reader, options);
121+
var value = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder?>(ref reader, options);
122122
if (value is not null)
123123
{
124124
agg.Order = value;
@@ -319,7 +319,7 @@ public DateHistogramAggregation(string name) : base(name)
319319

320320
[JsonInclude]
321321
[JsonPropertyName("order")]
322-
public Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder? Order { get; set; }
322+
public Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder? Order { get; set; }
323323

324324
[JsonInclude]
325325
[JsonPropertyName("params")]
@@ -369,11 +369,7 @@ public DateHistogramAggregationDescriptor() : base()
369369

370370
private Elastic.Clients.Elasticsearch.Duration? OffsetValue { get; set; }
371371

372-
private Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder? OrderValue { get; set; }
373-
374-
private HistogramOrderDescriptor OrderDescriptor { get; set; }
375-
376-
private Action<HistogramOrderDescriptor> OrderDescriptorAction { get; set; }
372+
private Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder? OrderValue { get; set; }
377373

378374
private Dictionary<string, object>? ParamsValue { get; set; }
379375

@@ -481,30 +477,12 @@ public DateHistogramAggregationDescriptor<TDocument> Offset(Elastic.Clients.Elas
481477
return Self;
482478
}
483479

484-
public DateHistogramAggregationDescriptor<TDocument> Order(Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder? order)
480+
public DateHistogramAggregationDescriptor<TDocument> Order(Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder? order)
485481
{
486-
OrderDescriptor = null;
487-
OrderDescriptorAction = null;
488482
OrderValue = order;
489483
return Self;
490484
}
491485

492-
public DateHistogramAggregationDescriptor<TDocument> Order(HistogramOrderDescriptor descriptor)
493-
{
494-
OrderValue = null;
495-
OrderDescriptorAction = null;
496-
OrderDescriptor = descriptor;
497-
return Self;
498-
}
499-
500-
public DateHistogramAggregationDescriptor<TDocument> Order(Action<HistogramOrderDescriptor> configure)
501-
{
502-
OrderValue = null;
503-
OrderDescriptor = null;
504-
OrderDescriptorAction = configure;
505-
return Self;
506-
}
507-
508486
public DateHistogramAggregationDescriptor<TDocument> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
509487
{
510488
ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
@@ -580,17 +558,7 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
580558
JsonSerializer.Serialize(writer, OffsetValue, options);
581559
}
582560

583-
if (OrderDescriptor is not null)
584-
{
585-
writer.WritePropertyName("order");
586-
JsonSerializer.Serialize(writer, OrderDescriptor, options);
587-
}
588-
else if (OrderDescriptorAction is not null)
589-
{
590-
writer.WritePropertyName("order");
591-
JsonSerializer.Serialize(writer, new HistogramOrderDescriptor(OrderDescriptorAction), options);
592-
}
593-
else if (OrderValue is not null)
561+
if (OrderValue is not null)
594562
{
595563
writer.WritePropertyName("order");
596564
JsonSerializer.Serialize(writer, OrderValue, options);
@@ -670,11 +638,7 @@ public DateHistogramAggregationDescriptor() : base()
670638

671639
private Elastic.Clients.Elasticsearch.Duration? OffsetValue { get; set; }
672640

673-
private Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder? OrderValue { get; set; }
674-
675-
private HistogramOrderDescriptor OrderDescriptor { get; set; }
676-
677-
private Action<HistogramOrderDescriptor> OrderDescriptorAction { get; set; }
641+
private Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder? OrderValue { get; set; }
678642

679643
private Dictionary<string, object>? ParamsValue { get; set; }
680644

@@ -788,30 +752,12 @@ public DateHistogramAggregationDescriptor Offset(Elastic.Clients.Elasticsearch.D
788752
return Self;
789753
}
790754

791-
public DateHistogramAggregationDescriptor Order(Elastic.Clients.Elasticsearch.Aggregations.HistogramOrder? order)
755+
public DateHistogramAggregationDescriptor Order(Elastic.Clients.Elasticsearch.Aggregations.AggregateOrder? order)
792756
{
793-
OrderDescriptor = null;
794-
OrderDescriptorAction = null;
795757
OrderValue = order;
796758
return Self;
797759
}
798760

799-
public DateHistogramAggregationDescriptor Order(HistogramOrderDescriptor descriptor)
800-
{
801-
OrderValue = null;
802-
OrderDescriptorAction = null;
803-
OrderDescriptor = descriptor;
804-
return Self;
805-
}
806-
807-
public DateHistogramAggregationDescriptor Order(Action<HistogramOrderDescriptor> configure)
808-
{
809-
OrderValue = null;
810-
OrderDescriptor = null;
811-
OrderDescriptorAction = configure;
812-
return Self;
813-
}
814-
815761
public DateHistogramAggregationDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
816762
{
817763
ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
@@ -887,17 +833,7 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
887833
JsonSerializer.Serialize(writer, OffsetValue, options);
888834
}
889835

890-
if (OrderDescriptor is not null)
891-
{
892-
writer.WritePropertyName("order");
893-
JsonSerializer.Serialize(writer, OrderDescriptor, options);
894-
}
895-
else if (OrderDescriptorAction is not null)
896-
{
897-
writer.WritePropertyName("order");
898-
JsonSerializer.Serialize(writer, new HistogramOrderDescriptor(OrderDescriptorAction), options);
899-
}
900-
else if (OrderValue is not null)
836+
if (OrderValue is not null)
901837
{
902838
writer.WritePropertyName("order");
903839
JsonSerializer.Serialize(writer, OrderValue, options);

0 commit comments

Comments
 (0)