7 changed files with 113 additions and 14 deletions
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0</TargetFrameworks> |
||||
|
<AssemblyName>LINGYUN.Abp.Elasticsearch.EsqlQuery</AssemblyName> |
||||
|
<PackageId>LINGYUN.Abp.Elasticsearch.EsqlQuery</PackageId> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Elastic.Clients.Esql" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Elasticsearch\LINGYUN.Abp.Elasticsearch.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,8 @@ |
|||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Elasticsearch.EsqlQuery; |
||||
|
|
||||
|
[DependsOn(typeof(AbpElasticsearchModule))] |
||||
|
public class AbpElasticsearchEsqlQueryModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
@ -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<long> GetCountAsync<TDocument>( |
||||
|
string indexName, |
||||
|
Expression<Func<TDocument, bool>> expression, |
||||
|
CancellationToken cancellationToken = default) where TDocument : class |
||||
|
{ |
||||
|
var client = ClientFactory.Create(); |
||||
|
|
||||
|
return await client.Esql.CreateQuery<TDocument>() |
||||
|
.Where(expression) |
||||
|
.AsEsqlQueryable() |
||||
|
.CountAsync(cancellationToken); |
||||
|
} |
||||
|
|
||||
|
public async override Task<List<TDocument>> GetListAsync<TDocument>( |
||||
|
string indexName, |
||||
|
Expression<Func<TDocument, bool>> 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<TDocument>().Where(expression); |
||||
|
if (!sorting.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
query = query.OrderBy(sorting); |
||||
|
} |
||||
|
|
||||
|
return await query |
||||
|
.PageBy(skipCount, maxResultCount) |
||||
|
.AsEsqlQueryable() |
||||
|
.ToListAsync(cancellationToken); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue