Skip to content

Commit 90bae5f

Browse files
committed
WIP - Elastic 9.0 Client Preview
elastic/elasticsearch-net#8496
1 parent 805cfdc commit 90bae5f

10 files changed

+174
-170
lines changed

src/Foundatio.Parsers.ElasticQueries/AggregationMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public record AggregationMap(string Name, object Value)
66
{
77
public string Name { get; set; } = Name;
88
public object Value { get; set; } = Value;
9-
public List<AggregationMap> Aggregations { get; } = new();
9+
public List<AggregationMap> Aggregations { get; } = new();
1010
public Dictionary<string, object> Meta { get; } = new();
1111
}

src/Foundatio.Parsers.ElasticQueries/ElasticMappingResolver.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public FieldMapping GetMapping(string field, bool followAlias = false)
5555

5656
if (_mappingCache.TryGetValue(field, out var mapping))
5757
{
58-
5958
if (followAlias && mapping.Found && mapping.Property is FieldAliasProperty fieldAlias)
6059
{
6160
_logger.LogTrace("Cached alias mapping: {Field}={FieldPath}:{FieldType}", field, mapping.FullPath, mapping.Property?.Type);
@@ -126,6 +125,7 @@ public FieldMapping GetMapping(string field, bool followAlias = false)
126125

127126
// coded properties sometimes have null Name properties
128127
string name = fieldMapping.TryGetName();
128+
// TODO: ?
129129
// if (name == null && fieldMapping is IPropertyWithClrOrigin clrOrigin && clrOrigin.ClrOrigin != null)
130130
// name = new PropertyName(clrOrigin.ClrOrigin);
131131

@@ -502,7 +502,7 @@ public static ElasticMappingResolver Create<T>(Func<TypeMappingDescriptor<T>, Ty
502502
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
503503

504504
// use first returned mapping because index could have been an index alias
505-
var mapping = response.Indices.Values.FirstOrDefault()?.Mappings;
505+
var mapping = response.Mappings.FirstOrDefault().Value?.Mappings;
506506
return mapping;
507507
}, logger);
508508
}
@@ -518,7 +518,7 @@ public static ElasticMappingResolver Create<T>(Func<TypeMappingDescriptor<T>, Ty
518518
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
519519

520520
// use first returned mapping because index could have been an index alias
521-
var mapping = response.Indices.Values.FirstOrDefault()?.Mappings;
521+
var mapping = response.Mappings.FirstOrDefault().Value?.Mappings;
522522
return mapping;
523523
}, logger);
524524
}
@@ -529,21 +529,21 @@ public static ElasticMappingResolver Create<T>(Func<TypeMappingDescriptor<T>, Ty
529529
return new ElasticMappingResolver(codeMapping, inferrer, getMapping, logger: logger);
530530
}
531531

532-
public static ElasticMappingResolver Create<T>(ElasticsearchClient client, ILogger logger = null)
533-
{
534-
logger ??= NullLogger.Instance;
532+
public static ElasticMappingResolver Create<T>(ElasticsearchClient client, ILogger logger = null)
533+
{
534+
logger ??= NullLogger.Instance;
535535

536-
return Create(() =>
537-
{
538-
client.Indices.Refresh(Indices.Index<T>());
539-
var response = client.Indices.GetMapping(new GetMappingRequest(Indices.Index<T>()));
540-
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
536+
return Create(() =>
537+
{
538+
client.Indices.Refresh(Indices.Index<T>());
539+
var response = client.Indices.GetMapping(new GetMappingRequest(Indices.Index<T>()));
540+
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
541541

542-
// use first returned mapping because index could have been an index alias
543-
var mapping = response.Indices.Values.FirstOrDefault()?.Mappings;
544-
return mapping;
545-
}, client.Infer, logger);
546-
}
542+
// use first returned mapping because index could have been an index alias
543+
var mapping = response.Mappings.FirstOrDefault().Value?.Mappings;
544+
return mapping;
545+
}, client.Infer, logger);
546+
}
547547

548548
public static ElasticMappingResolver Create(ElasticsearchClient client, string index, ILogger logger = null)
549549
{
@@ -556,7 +556,7 @@ public static ElasticMappingResolver Create(ElasticsearchClient client, string i
556556
logger.LogTrace("GetMapping: {Request}", response.GetRequest(false, true));
557557

558558
// use first returned mapping because index could have been an index alias
559-
var mapping = response.Indices.Values.FirstOrDefault()?.Mappings;
559+
var mapping = response.Mappings.FirstOrDefault().Value?.Mappings;
560560
return mapping;
561561
}, client.Infer, logger);
562562
}

src/Foundatio.Parsers.ElasticQueries/Extensions/DefaultAggregationNodeExtensions.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static async Task<AggregationMap> GetDefaultAggregationAsync(this GroupNo
4949

5050
case AggregationType.GeoHashGrid:
5151
var precision = new GeohashPrecision(1);
52-
if (!String.IsNullOrEmpty(node.UnescapedProximity) && Double.TryParse(node.UnescapedProximity, out double parsedPrecision))
52+
if (!String.IsNullOrEmpty(node.UnescapedProximity) && Int64.TryParse(node.UnescapedProximity, out long parsedPrecision))
5353
{
5454
if (parsedPrecision is < 1 or > 12)
5555
throw new ArgumentOutOfRangeException(nameof(node.UnescapedProximity), "Precision must be between 1 and 12");
@@ -162,7 +162,7 @@ public static async Task<AggregationMap> GetDefaultAggregationAsync(this TermNod
162162

163163
case AggregationType.GeoHashGrid:
164164
var precision = new GeohashPrecision(1);
165-
if (!String.IsNullOrEmpty(node.UnescapedProximity) && Double.TryParse(node.UnescapedProximity, out double parsedPrecision))
165+
if (!String.IsNullOrEmpty(node.UnescapedProximity) && Int64.TryParse(node.UnescapedProximity, out long parsedPrecision))
166166
{
167167
if (parsedPrecision is < 1 or > 12)
168168
throw new ArgumentOutOfRangeException(nameof(node.UnescapedProximity), "Precision must be between 1 and 12");
@@ -240,9 +240,7 @@ private static AggregationMap GetDateHistogramAggregation(string originalField,
240240
var start = context.GetDate("StartDate");
241241
var end = context.GetDate("EndDate");
242242
bool isValidRange = start.HasValue && start.Value > DateTime.MinValue && end.HasValue && end.Value < DateTime.MaxValue && start.Value <= end.Value;
243-
// TODO: https://github.com/elastic/elasticsearch-net/issues/8338
244-
//var bounds = isValidRange ? new ExtendedBoundsDate { Min = start.Value, Max = end.Value } : null;
245-
var bounds = isValidRange ? new ExtendedBoundsDate { Min = new FieldDateMath(DateMath.Anchored(start.Value).ToString()), Max = new FieldDateMath(DateMath.Anchored(end.Value).ToString()) } : null;
243+
var bounds = isValidRange ? new ExtendedBounds<DateTime> { Min = start.Value, Max = end.Value } : null;
246244

247245
var interval = GetInterval(proximity, start, end);
248246
string timezone = TryConvertTimeUnitToUtcOffset(boost);
@@ -252,7 +250,8 @@ private static AggregationMap GetDateHistogramAggregation(string originalField,
252250
MinDocCount = 0,
253251
Format = "date_optional_time",
254252
TimeZone = timezone,
255-
ExtendedBounds = bounds
253+
//ExtendedBounds = bounds
254+
// TODO: https://github.com/elastic/elasticsearch-net/issues/8496
256255
};
257256

258257
interval.Match(d => agg.CalendarInterval = d, f => agg.FixedInterval = f);

src/Foundatio.Parsers.ElasticQueries/Extensions/DefaultSortNodeExtensions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ public static SortOptions GetDefaultSort(this TermNode node, IQueryVisitorContex
1818
string field = elasticContext.MappingResolver.GetSortFieldName(node.UnescapedField);
1919
var fieldType = elasticContext.MappingResolver.GetFieldType(field);
2020

21-
return SortOptions.Field(field, new FieldSort
21+
return new SortOptions
2222
{
23-
UnmappedType = fieldType == FieldType.None ? FieldType.Keyword : fieldType,
24-
Order = node.IsNodeOrGroupNegated() ? SortOrder.Desc : SortOrder.Asc
25-
});
23+
Field = new FieldSort(field)
24+
{
25+
UnmappedType = fieldType == FieldType.None ? FieldType.Keyword : fieldType,
26+
Order = node.IsNodeOrGroupNegated() ? SortOrder.Desc : SortOrder.Asc
27+
}
28+
};
2629
}
2730
}

src/Foundatio.Parsers.ElasticQueries/Extensions/ElasticExtensions.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
using Elastic.Clients.Elasticsearch;
1010
using Elastic.Clients.Elasticsearch.Aggregations;
1111
using Elastic.Clients.Elasticsearch.Mapping;
12+
using Elastic.Clients.Elasticsearch.QueryDsl;
1213
using Elastic.Transport.Products.Elasticsearch;
1314
using Microsoft.Extensions.Logging;
1415

1516
namespace Foundatio.Parsers.ElasticQueries.Extensions;
1617

1718
public static class ElasticExtensions
1819
{
20+
public static bool TryGet<T>(this Query query, out T result)
21+
{
22+
// TODO: until: https://github.com/elastic/elasticsearch-net/issues/8496
23+
result = default;
24+
return false;
25+
}
26+
1927
public static string TryGetName(this IProperty property)
2028
{
21-
// TODO until: https://github.com/elastic/elasticsearch-net/issues/8336
29+
// TODO: until: https://github.com/elastic/elasticsearch-net/issues/8336
2230
return null;
2331
}
2432

src/Foundatio.Parsers.ElasticQueries/Foundatio.Parsers.ElasticQueries.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\build\common.props" />
33
<ItemGroup>
4-
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.17.1" />
4+
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="9.0.0-preview.1" />
55
<PackageReference Include="Exceptionless.DateTimeExtensions" Version="3.4.3" />
66
<PackageReference Include="System.Text.Json" Version="8.0.5" />
77
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0" />

0 commit comments

Comments
 (0)