Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Elastic.Clients.Elasticsearch #84

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a4b976f
Use elasticsearch 8
niemyjski Aug 30, 2024
c6be6c7
WIP - Upgrade to the new Elasticsearch client
niemyjski Aug 30, 2024
aa8e564
Updated elastic
niemyjski Sep 12, 2024
3eec87f
WIP - Added polyfill for what will be added in next client.
niemyjski Sep 12, 2024
5dd521e
Added aggregation container that can be used to map to a descriptor
niemyjski Sep 12, 2024
50c0906
More fixes
niemyjski Sep 12, 2024
3707d56
More work to detect bucket aggs.
niemyjski Sep 12, 2024
1175b50
Commented out code / hacks to get it to compile
niemyjski Sep 12, 2024
020968c
WIP: Fix test compiler errors.
niemyjski Sep 12, 2024
104d5e4
WIP - TESTS
niemyjski Sep 12, 2024
af1f553
WIP - Test updates
niemyjski Sep 13, 2024
001bce4
Upgraded deprecated sync test method.
niemyjski Sep 13, 2024
799f7f3
Small updates
niemyjski Sep 13, 2024
afc472f
More test updates
niemyjski Sep 16, 2024
4b78492
Fixed a query bug
niemyjski Sep 16, 2024
2e1bed2
Merge branch 'main' into feature/elastic-client
niemyjski Oct 28, 2024
cd2e310
Merge branch 'main' into feature/elastic-client
niemyjski Nov 22, 2024
9859e81
Updated to latest client
niemyjski Nov 22, 2024
9526f2b
Merge branch 'main' into feature/elastic-client
niemyjski Nov 26, 2024
d4e8c8f
Merge branch 'main' into feature/elastic-client
niemyjski Jan 24, 2025
b679378
Updated elastic version
niemyjski Jan 24, 2025
a822889
Merge remote-tracking branch 'origin/main' into feature/elastic-client
niemyjski Feb 28, 2025
7d9a25e
WIP: Fixed more compiler errors.
niemyjski Feb 28, 2025
805cfdc
WIP: Down to 71 compiler errors
niemyjski Feb 28, 2025
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
Prev Previous commit
Next Next commit
WIP - Added polyfill for what will be added in next client.
niemyjski committed Sep 12, 2024
commit 3eec87f5f7278563f20a39924918af90cd6a3f6a
39 changes: 22 additions & 17 deletions src/Foundatio.Parsers.ElasticQueries/ElasticMappingResolver.cs
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ public FieldMapping GetMapping(string field, bool followAlias = false)
if (currentProperties != null)
fieldMapping = ((IDictionary<PropertyName, IProperty>)currentProperties).Values.FirstOrDefault(m =>
{
string propertyName = _inferrer.PropertyName(m?.Name);
string propertyName = _inferrer.PropertyName(m?.TryGetName());
return propertyName != null && propertyName.Equals(fieldPart, StringComparison.OrdinalIgnoreCase);
});

@@ -125,13 +125,14 @@ public FieldMapping GetMapping(string field, bool followAlias = false)
}

// coded properties sometimes have null Name properties
if (fieldMapping.Name == null && fieldMapping is IPropertyWithClrOrigin clrOrigin && clrOrigin.ClrOrigin != null)
fieldMapping.Name = new PropertyName(clrOrigin.ClrOrigin);
string name = fieldMapping.TryGetName();
if (name == null && fieldMapping is IPropertyWithClrOrigin clrOrigin && clrOrigin.ClrOrigin != null)
name = new PropertyName(clrOrigin.ClrOrigin);

if (depth == 0)
resolvedFieldName += _inferrer.PropertyName(fieldMapping.Name);
resolvedFieldName += _inferrer.PropertyName(name);
else
resolvedFieldName += "." + _inferrer.PropertyName(fieldMapping.Name);
resolvedFieldName += "." + _inferrer.PropertyName(name);

if (depth == fieldParts.Length - 1)
{
@@ -415,7 +416,7 @@ private Properties MergeProperties(Properties codeProperties, Properties serverP

mergedCodeProperties[kvp.Key] = new FieldAliasProperty
{
Meta = aliasProperty.Meta,
//LocalMetadata = aliasProperty.LocalMetadata,
Path = _inferrer?.Field(aliasProperty.Path) ?? aliasProperty.Path,
Name = aliasProperty.Name
};
@@ -431,19 +432,23 @@ private Properties MergeProperties(Properties codeProperties, Properties serverP
foreach (var serverProperty in serverProperties)
{
var merged = serverProperty.Value;
if (mergedCodeProperties.TryGetProperty(serverProperty.Key, out var codeProperty))
merged.LocalMetadata = codeProperty.LocalMetadata;
// if (mergedCodeProperties.TryGetProperty(serverProperty.Key, out var codeProperty))
// merged.LocalMetadata = codeProperty.LocalMetadata;

switch (merged)
if (mergedCodeProperties.TryGetProperty(serverProperty.Key, out var codeProperty))
{
case ObjectProperty objectProperty:
var codeObjectProperty = codeProperty as ObjectProperty;
objectProperty.Properties = MergeProperties(codeObjectProperty?.Properties, objectProperty.Properties);
break;
case TextProperty textProperty:
var codeTextProperty = codeProperty as TextProperty;
textProperty.Fields = MergeProperties(codeTextProperty?.Fields, textProperty.Fields);
break;
switch (merged)
{
case ObjectProperty objectProperty:
var codeObjectProperty = codeProperty as ObjectProperty;
objectProperty.Properties =
MergeProperties(codeObjectProperty?.Properties, objectProperty.Properties);
break;
case TextProperty textProperty:
var codeTextProperty = codeProperty as TextProperty;
textProperty.Fields = MergeProperties(codeTextProperty?.Fields, textProperty.Fields);
break;
}
}

properties.Add(serverProperty.Key, merged);
Original file line number Diff line number Diff line change
@@ -8,13 +8,20 @@
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Elastic.Clients.Elasticsearch.Aggregations;
using Elastic.Clients.Elasticsearch.Mapping;
using Elastic.Transport.Products.Elasticsearch;
using Microsoft.Extensions.Logging;

namespace Foundatio.Parsers.ElasticQueries.Extensions;

public static class ElasticExtensions
{
public static string TryGetName(this IProperty property)
{
// TODO until: https://github.com/elastic/elasticsearch-net/issues/8336
return null;
}

public static TermsInclude AddValue(this TermsInclude include, string value)
{
if (include?.Values == null)
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ public override async Task VisitAsync(GroupNode node, IQueryVisitorContext conte

Query query = await node.GetQueryAsync(() => node.GetDefaultQueryAsync(context)).ConfigureAwait(false);
Query container = query;
var nested = query as NestedQuery;
if (nested != null && node.Parent != null)
if (query.TryGet<NestedQuery>(out var nested) && node.Parent != null)
container = null;

foreach (var child in node.Children.OfType<IFieldQueryNode>())
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public override void Visit(TermNode node, IQueryVisitorContext context)
return;

var sort = node.GetSort(() => node.GetDefaultSort(context));
if (sort.AdditionalPropertyName == null)
if (sort.SortKey == null)
return;

_fields.Add(sort);