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 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.24
image: docker.elastic.co/elasticsearch/elasticsearch:8.16.1
environment:
discovery.type: single-node
xpack.security.enabled: 'false'
Expand All @@ -19,7 +19,7 @@ services:
depends_on:
elasticsearch:
condition: service_healthy
image: docker.elastic.co/kibana/kibana:7.17.24
image: docker.elastic.co/kibana/kibana:8.16.1
ports:
- 5601:5601
networks:
Expand Down
11 changes: 11 additions & 0 deletions src/Foundatio.Parsers.ElasticQueries/AggregationMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace Foundatio.Parsers.ElasticQueries;

public record AggregationMap(string Name, object Value)
{
public string Name { get; set; } = Name;
public object Value { get; set; } = Value;
public List<AggregationMap> Aggregations { get; } = new();
public Dictionary<string, object> Meta { get; } = new();
}
211 changes: 123 additions & 88 deletions src/Foundatio.Parsers.ElasticQueries/ElasticMappingResolver.cs

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions src/Foundatio.Parsers.ElasticQueries/ElasticQueryParser.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Elastic.Clients.Elasticsearch.Aggregations;
using Elastic.Clients.Elasticsearch.QueryDsl;
using Foundatio.Parsers.ElasticQueries.Extensions;
using Foundatio.Parsers.ElasticQueries.Visitors;
using Foundatio.Parsers.LuceneQueries;
using Foundatio.Parsers.LuceneQueries.Extensions;
using Foundatio.Parsers.LuceneQueries.Nodes;
using Foundatio.Parsers.LuceneQueries.Visitors;
using Nest;
using Pegasus.Common;

namespace Foundatio.Parsers.ElasticQueries;
Expand Down Expand Up @@ -158,7 +160,7 @@ public async Task<QueryValidationResult> ValidateQueryAsync(string query, QueryV
return context.GetValidationResult();
}

public async Task<QueryContainer> BuildQueryAsync(string query, IElasticQueryVisitorContext context = null)
public async Task<Query> BuildQueryAsync(string query, IElasticQueryVisitorContext context = null)
{
context ??= new ElasticQueryVisitorContext();
context.QueryType = QueryTypes.Query;
Expand All @@ -169,7 +171,7 @@ public async Task<QueryContainer> BuildQueryAsync(string query, IElasticQueryVis
return await BuildQueryAsync(result, context).ConfigureAwait(false);
}

public async Task<QueryContainer> BuildQueryAsync(IQueryNode query, IElasticQueryVisitorContext context = null)
public async Task<Query> BuildQueryAsync(IQueryNode query, IElasticQueryVisitorContext context = null)
{
context ??= new ElasticQueryVisitorContext();
var q = await query.GetQueryAsync() ?? new MatchAllQuery();
Expand All @@ -195,7 +197,7 @@ public async Task<QueryValidationResult> ValidateAggregationsAsync(string query,
return context.GetValidationResult();
}

public async Task<AggregationContainer> BuildAggregationsAsync(string aggregations, IElasticQueryVisitorContext context = null)
public async Task<AggregationMap> BuildAggregationsAsync(string aggregations, IElasticQueryVisitorContext context = null)
{
context ??= new ElasticQueryVisitorContext();
context.QueryType = QueryTypes.Aggregation;
Expand All @@ -207,7 +209,7 @@ public async Task<AggregationContainer> BuildAggregationsAsync(string aggregatio
}

#pragma warning disable IDE0060 // Remove unused parameter
public async Task<AggregationContainer> BuildAggregationsAsync(IQueryNode aggregations, IElasticQueryVisitorContext context = null)
public async Task<AggregationMap> BuildAggregationsAsync(IQueryNode aggregations, IElasticQueryVisitorContext context = null)
{
if (aggregations == null)
return null;
Expand All @@ -227,7 +229,7 @@ public async Task<QueryValidationResult> ValidateSortAsync(string query, QueryVa
return context.GetValidationResult();
}

public async Task<IEnumerable<IFieldSort>> BuildSortAsync(string sort, IElasticQueryVisitorContext context = null)
public async Task<IEnumerable<SortOptions>> BuildSortAsync(string sort, IElasticQueryVisitorContext context = null)
{
context ??= new ElasticQueryVisitorContext();
context.QueryType = QueryTypes.Sort;
Expand All @@ -238,7 +240,7 @@ public async Task<IEnumerable<IFieldSort>> BuildSortAsync(string sort, IElasticQ
return await BuildSortAsync(result, context).ConfigureAwait(false);
}

public Task<IEnumerable<IFieldSort>> BuildSortAsync(IQueryNode sort, IElasticQueryVisitorContext context = null)
public Task<IEnumerable<SortOptions>> BuildSortAsync(IQueryNode sort, IElasticQueryVisitorContext context = null)
{
context ??= new ElasticQueryVisitorContext();
return GetSortFieldsVisitor.RunAsync(sort, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Elastic.Clients.Elasticsearch.Mapping;
using Foundatio.Parsers.ElasticQueries.Visitors;
using Foundatio.Parsers.LuceneQueries;
using Foundatio.Parsers.LuceneQueries.Visitors;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Nest;

namespace Foundatio.Parsers.ElasticQueries;

Expand Down Expand Up @@ -285,35 +286,35 @@ public ElasticQueryParserConfiguration AddAggregationVisitorAfter<T>(IChainableQ

#endregion

public ElasticQueryParserConfiguration UseMappings<T>(Func<TypeMappingDescriptor<T>, TypeMappingDescriptor<T>> mappingBuilder, IElasticClient client, string index) where T : class
public ElasticQueryParserConfiguration UseMappings<T>(Func<TypeMappingDescriptor<T>, TypeMapping> mappingBuilder, ElasticsearchClient client, string index) where T : class
{
MappingResolver = ElasticMappingResolver.Create<T>(mappingBuilder, client, index, logger: _logger);

return this;
}

public ElasticQueryParserConfiguration UseMappings<T>(Func<TypeMappingDescriptor<T>, TypeMappingDescriptor<T>> mappingBuilder, Inferrer inferrer, Func<ITypeMapping> getMapping) where T : class
public ElasticQueryParserConfiguration UseMappings<T>(Func<TypeMappingDescriptor<T>, TypeMapping> mappingBuilder, Inferrer inferrer, Func<TypeMapping> getMapping) where T : class
{
MappingResolver = ElasticMappingResolver.Create<T>(mappingBuilder, inferrer, getMapping, logger: _logger);

return this;
}

public ElasticQueryParserConfiguration UseMappings<T>(IElasticClient client)
public ElasticQueryParserConfiguration UseMappings<T>(ElasticsearchClient client)
{
MappingResolver = ElasticMappingResolver.Create<T>(client, logger: _logger);

return this;
}

public ElasticQueryParserConfiguration UseMappings(IElasticClient client, string index)
public ElasticQueryParserConfiguration UseMappings(ElasticsearchClient client, string index)
{
MappingResolver = ElasticMappingResolver.Create(client, index, logger: _logger);

return this;
}

public ElasticQueryParserConfiguration UseMappings(Func<ITypeMapping> getMapping, Inferrer inferrer = null)
public ElasticQueryParserConfiguration UseMappings(Func<TypeMapping> getMapping, Inferrer inferrer = null)
{
MappingResolver = ElasticMappingResolver.Create(getMapping, inferrer, logger: _logger);

Expand Down
Loading
Loading