diff --git a/Directory.Packages.props b/Directory.Packages.props
index eae775c5f..0fe130716 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -360,7 +360,7 @@
-
+
diff --git a/aspnet-core/LINGYUN.MicroService.All.slnx b/aspnet-core/LINGYUN.MicroService.All.slnx
index b531257ce..7b6d3d7a1 100644
--- a/aspnet-core/LINGYUN.MicroService.All.slnx
+++ b/aspnet-core/LINGYUN.MicroService.All.slnx
@@ -155,6 +155,7 @@
+
@@ -525,6 +526,7 @@
+
@@ -538,6 +540,8 @@
+
+
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj
new file mode 100644
index 000000000..ccb6094d5
--- /dev/null
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0
+ LINGYUN.Abp.Elasticsearch.EsqlQuery
+ LINGYUN.Abp.Elasticsearch.EsqlQuery
+ false
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryModule.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryModule.cs
new file mode 100644
index 000000000..4b2c9c7a8
--- /dev/null
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryModule.cs
@@ -0,0 +1,8 @@
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
+
+[DependsOn(typeof(AbpElasticsearchModule))]
+public class AbpElasticsearchEsqlQueryModule : AbpModule
+{
+}
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs
new file mode 100644
index 000000000..6d22f25b8
--- /dev/null
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs
@@ -0,0 +1,60 @@
+using Elastic.Clients.Elasticsearch;
+using Elastic.Esql.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Linq.Expressions;
+using System.Threading;
+using System.Threading.Tasks;
+using Volo.Abp.DependencyInjection;
+
+namespace LINGYUN.Abp.Elasticsearch.EsqlQuery;
+
+[Dependency(ReplaceServices = true)]
+public class EsqlExpressionQueryService : ExpressionQueryService, ITransientDependency
+{
+ public EsqlExpressionQueryService(
+ IElasticsearchClientFactory clientFactory,
+ IExpressionQueryTranslator expressionQueryTranslator)
+ : base(clientFactory, expressionQueryTranslator)
+ {
+ }
+
+ public async override Task GetCountAsync(
+ string indexName,
+ Expression> expression,
+ CancellationToken cancellationToken = default) where TDocument : class
+ {
+ var client = ClientFactory.Create();
+
+ return await client.Esql.CreateQuery()
+ .Where(expression)
+ .AsEsqlQueryable()
+ .CountAsync(cancellationToken);
+ }
+
+ public async override Task> GetListAsync(
+ string indexName,
+ Expression> expression,
+ string? sorting = null,
+ int maxResultCount = 50,
+ int skipCount = 0,
+ Fields? sourceExcludes = null,
+ Fields? sourceIncludes = null,
+ CancellationToken cancellationToken = default) where TDocument : class
+ {
+ var client = ClientFactory.Create();
+
+ var query = client.Esql.CreateQuery().Where(expression);
+ if (!sorting.IsNullOrWhiteSpace())
+ {
+ query = query.OrderBy(sorting);
+ }
+
+ return await query
+ .PageBy(skipCount, maxResultCount)
+ .AsEsqlQueryable()
+ .ToListAsync(cancellationToken);
+ }
+}
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs
index c7f4be8d2..888c34fb2 100644
--- a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs
@@ -12,24 +12,24 @@ namespace LINGYUN.Abp.Elasticsearch;
public class ExpressionQueryService : IExpressionQueryService, ITransientDependency
{
- private readonly IElasticsearchClientFactory _clientFactory;
- private readonly IExpressionQueryTranslator _expressionQueryTranslator;
+ protected IElasticsearchClientFactory ClientFactory { get; }
+ protected IExpressionQueryTranslator ExpressionQueryTranslator { get; }
public ExpressionQueryService(
IElasticsearchClientFactory clientFactory,
IExpressionQueryTranslator expressionQueryTranslator)
{
- _clientFactory = clientFactory;
- _expressionQueryTranslator = expressionQueryTranslator;
+ ClientFactory = clientFactory;
+ ExpressionQueryTranslator = expressionQueryTranslator;
}
public async virtual Task GetCountAsync(
string indexName,
Expression> expression,
- CancellationToken cancellationToken = default)
+ CancellationToken cancellationToken = default) where TDocument : class
{
- var client = _clientFactory.Create();
- var query = await _expressionQueryTranslator.TranslateAsync(indexName, expression);
+ var client = ClientFactory.Create();
+ var query = await ExpressionQueryTranslator.TranslateAsync(indexName, expression);
var response = await client.CountAsync(dsl =>
dsl.Indices(indexName).Query(query),
@@ -46,10 +46,10 @@ public class ExpressionQueryService : IExpressionQueryService, ITransientDepende
int skipCount = 0,
Fields? sourceExcludes = null,
Fields? sourceIncludes = null,
- CancellationToken cancellationToken = default)
+ CancellationToken cancellationToken = default) where TDocument : class
{
- var client = _clientFactory.Create();
- var query = await _expressionQueryTranslator.TranslateAsync(indexName, expression);
+ var client = ClientFactory.Create();
+ var query = await ExpressionQueryTranslator.TranslateAsync(indexName, expression);
SortOptions[]? sorts = null;
if (!sorting.IsNullOrWhiteSpace())
@@ -61,7 +61,10 @@ public class ExpressionQueryService : IExpressionQueryService, ITransientDepende
{
new SortOptions
{
- Field = new FieldSort(new Field(sorting)),
+ Field = new FieldSort(new Field(sorting))
+ {
+ Order = sortOrder,
+ },
}
};
}
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs
index aef5b89cf..65e24c803 100644
--- a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs
@@ -20,7 +20,7 @@ public interface IExpressionQueryService
Task GetCountAsync(
string indexName,
Expression> expression,
- CancellationToken cancellationToken = default);
+ CancellationToken cancellationToken = default) where TDocument : class;
///
/// 查询符合条件的文档列表
///
@@ -42,5 +42,5 @@ public interface IExpressionQueryService
int skipCount = 0,
Fields? sourceExcludes = null,
Fields? sourceIncludes = null,
- CancellationToken cancellationToken = default);
+ CancellationToken cancellationToken = default) where TDocument : class;
}