Browse Source

feat: Integrate Esql client functionality

pull/1552/head
colin 1 week ago
parent
commit
68ec5c1055
  1. 2
      Directory.Packages.props
  2. 4
      aspnet-core/LINGYUN.MicroService.All.slnx
  3. 24
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj
  4. 8
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/AbpElasticsearchEsqlQueryModule.cs
  5. 60
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN/Abp/Elasticsearch/EsqlQuery/EsqlExpressionQueryService.cs
  6. 25
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ExpressionQueryService.cs
  7. 4
      aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs

2
Directory.Packages.props

@ -360,7 +360,7 @@
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NEST" Version="7.17.5" />
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.19.4" />
<PackageVersion Include="NRules" Version="0.9.2" />
<PackageVersion Include="Elastic.Clients.Esql" Version="0.11.0" />
<PackageVersion Include="Ocelot.Provider.Polly" Version="20.0.0" />
<PackageVersion Include="OllamaSharp" Version="5.4.20" />
<PackageVersion Include="ModelContextProtocol" Version="1.1.0" />

4
aspnet-core/LINGYUN.MicroService.All.slnx

@ -155,6 +155,7 @@
<Project Path="framework/efcore/LINGYUN.Abp.EntityFrameworkCore.MySQL.Microting/LINGYUN.Abp.EntityFrameworkCore.MySQL.Microting.csproj" />
</Folder>
<Folder Name="/framework/elasticsearch/">
<Project Path="framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj" Id="ef34fa8c-55e4-4976-852b-20e94c355ab5" />
<Project Path="framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN.Abp.Elasticsearch.csproj" />
</Folder>
<Folder Name="/framework/entity-change/">
@ -525,6 +526,7 @@
<Folder Name="/tests/">
<Project Path="tests/LINGYUN.Abp.Aliyun.Tests/LINGYUN.Abp.Aliyun.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.AuditLogging.Elasticsearch.Tests/LINGYUN.Abp.AuditLogging.Elasticsearch.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.AuditLogging.Tests/LINGYUN.Abp.AuditLogging.Tests.csproj" Id="a360d3e3-0cef-433c-a866-77abd64d8a52" />
<Project Path="tests/LINGYUN.Abp.BlobStoring.Aliyun.Tests/LINGYUN.Abp.BlobStoring.Aliyun.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.BlobStoring.Nexus.Tests/LINGYUN.Abp.BlobStoring.Nexus.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.DataProtection.Tests/LINGYUN.Abp.DataProtection.Tests.csproj" />
@ -538,6 +540,8 @@
<Project Path="tests/LINGYUN.Abp.Localization.Xml.Tests/LINGYUN.Abp.Localization.Xml.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.Location.Baidu.Tests/LINGYUN.Abp.Location.Baidu.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.Location.Tencent.Tests/LINGYUN.Abp.Location.Tencent.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.Logging.Serilog.Elasticsearch.Tests/LINGYUN.Abp.Logging.Serilog.Elasticsearch.Tests.csproj" Id="d9b9a706-000c-4344-8eac-27ee78fcbb2a" />
<Project Path="tests/LINGYUN.Abp.Logging.Tests/LINGYUN.Abp.Logging.Tests.csproj" Id="1e05270f-6652-443d-b76f-5d4360f2722e" />
<Project Path="tests/LINGYUN.Abp.Rules.RulesEngine.Tests/LINGYUN.Abp.Rules.RulesEngine.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.Sms.Platform.Tests/LINGYUN.Abp.Sms.Platform.Tests.csproj" />
<Project Path="tests/LINGYUN.Abp.TestBase/LINGYUN.Abp.TestsBase.csproj" />

24
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch.EsqlQuery/LINGYUN.Abp.Elasticsearch.EsqlQuery.csproj

@ -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>

8
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
{
}

60
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<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);
}
}

25
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<long> GetCountAsync<TDocument>(
string indexName,
Expression<Func<TDocument, bool>> 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<TDocument>(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,
},
}
};
}

4
aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IExpressionQueryService.cs

@ -20,7 +20,7 @@ public interface IExpressionQueryService
Task<long> GetCountAsync<TDocument>(
string indexName,
Expression<Func<TDocument, bool>> expression,
CancellationToken cancellationToken = default);
CancellationToken cancellationToken = default) where TDocument : class;
/// <summary>
/// 查询符合条件的文档列表
/// </summary>
@ -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;
}

Loading…
Cancel
Save