diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs
index 2159d89b9..03c421f20 100644
--- a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs
@@ -1,8 +1,9 @@
-using Elasticsearch.Net;
-using Nest;
+using Elastic.Clients.Elasticsearch;
+using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq;
+using static Elastic.Clients.Elasticsearch.ElasticsearchClientSettings;
namespace LINGYUN.Abp.Elasticsearch
{
@@ -15,56 +16,90 @@ namespace LINGYUN.Abp.Elasticsearch
/// 默认:false
///
public bool FieldCamelCase { get; set; }
+ ///
+ /// When set to true will disable (de)serializing directly to the request and response stream and return a byte[] copy of the raw request and response.
+ /// Defaults to false.
+ ///
public bool DisableDirectStreaming { get; set; }
public string NodeUris { get; set; }
public int ConnectionLimit { get; set; }
+ ///
+ /// `Base64ApiKey` for Elastic Cloud style encoded api keys
+ ///
+ public string? Base64ApiKey { get; set; }
+ ///
+ /// `ApiKey` for simple secret token
+ ///
+ public string? ApiKey { get; set; }
+ ///
+ /// `UserName` for basic authentication
+ ///
public string? UserName { get; set; }
+ ///
+ /// `Password` for basic authentication
+ ///
public string? Password { get; set; }
- public TimeSpan ConnectionTimeout { get; set; }
- public IConnection Connection { get; set; }
- public ConnectionSettings.SourceSerializerFactory SerializerFactory { get; set; }
+ ///
+ /// Default: 60s
+ ///
+ public TimeSpan RequestTimeout { get; set; }
+ ///
+ ///
+ ///
+ public IRequestInvoker RequestInvoker { get; set; }
+ public SourceSerializerFactory SerializerFactory { get; set; }
public AbpElasticsearchOptions()
{
- ConnectionLimit = ConnectionConfiguration.DefaultConnectionLimit;
- ConnectionTimeout = ConnectionConfiguration.DefaultTimeout;
+ ConnectionLimit = TransportConfiguration.DefaultConnectionLimit;
+ // Default: 60s
+ // See: https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/_options_on_elasticsearchclientsettings
+ RequestTimeout = TimeSpan.FromSeconds(60);
}
- internal IConnectionSettingsValues CreateConfiguration()
+ internal IElasticsearchClientSettings CreateClientSettings()
{
- IConnectionPool connectionPool;
+ NodePool nodePool;
IEnumerable nodes = NodeUris
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(uriString => new Uri(uriString));
if (nodes.Count() == 1)
{
- connectionPool = new SingleNodeConnectionPool(nodes.First());
+ nodePool = new SingleNodePool(nodes.First());
}
else
{
- connectionPool = new StaticConnectionPool(nodes);
+ nodePool = new StaticNodePool(nodes);
}
- var configuration = new ConnectionSettings(
- connectionPool,
- Connection,
+ var clientSettings = new ElasticsearchClientSettings(
+ nodePool,
+ RequestInvoker,
SerializerFactory)
.ConnectionLimit(ConnectionLimit)
- .RequestTimeout(ConnectionTimeout);
+ .RequestTimeout(RequestTimeout);
if (!FieldCamelCase)
{
- configuration.DefaultFieldNameInferrer((name) => name);
+ clientSettings.DefaultFieldNameInferrer((name) => name);
}
- if (!UserName.IsNullOrWhiteSpace())
+ if (!Base64ApiKey.IsNullOrWhiteSpace())
+ {
+ clientSettings.Authentication(new Base64ApiKey(Base64ApiKey));
+ }
+ else if (!ApiKey.IsNullOrWhiteSpace())
+ {
+ clientSettings.Authentication(new ApiKey(ApiKey));
+ }
+ else if (!UserName.IsNullOrWhiteSpace() && !Password.IsNullOrWhiteSpace())
{
- configuration.BasicAuthentication(UserName, Password);
+ clientSettings.Authentication(new BasicAuthentication(UserName, Password));
}
- configuration.DisableDirectStreaming(DisableDirectStreaming);
+ clientSettings.DisableDirectStreaming(DisableDirectStreaming);
- return configuration;
+ return clientSettings;
}
}
}
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ElasticsearchClientFactory.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ElasticsearchClientFactory.cs
index dd3c122fd..1b4704080 100644
--- a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ElasticsearchClientFactory.cs
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/ElasticsearchClientFactory.cs
@@ -1,5 +1,5 @@
-using Microsoft.Extensions.Options;
-using Nest;
+using Elastic.Clients.Elasticsearch;
+using Microsoft.Extensions.Options;
using System;
using Volo.Abp.DependencyInjection;
@@ -8,23 +8,23 @@ namespace LINGYUN.Abp.Elasticsearch
public class ElasticsearchClientFactory : IElasticsearchClientFactory, ISingletonDependency
{
private readonly AbpElasticsearchOptions _options;
- private readonly Lazy _lazyClient;
+ private readonly Lazy _lazyClient;
public ElasticsearchClientFactory(
IOptions options)
{
_options = options.Value;
- _lazyClient = new Lazy(CreateClient);
+ _lazyClient = new Lazy(CreateClient);
}
- public IElasticClient Create() => _lazyClient.Value;
+ public ElasticsearchClient Create() => _lazyClient.Value;
- protected virtual IElasticClient CreateClient()
+ protected virtual ElasticsearchClient CreateClient()
{
- var configuration = _options.CreateConfiguration();
+ var configuration = _options.CreateClientSettings();
- var client = new ElasticClient(configuration);
+ var client = new ElasticsearchClient(configuration);
return client;
}
diff --git a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IElasticsearchClientFactory.cs b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IElasticsearchClientFactory.cs
index d10980019..16f4c6c9c 100644
--- a/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IElasticsearchClientFactory.cs
+++ b/aspnet-core/framework/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/IElasticsearchClientFactory.cs
@@ -1,9 +1,9 @@
-using Nest;
+using Elastic.Clients.Elasticsearch;
namespace LINGYUN.Abp.Elasticsearch
{
public interface IElasticsearchClientFactory
{
- IElasticClient Create();
+ ElasticsearchClient Create();
}
}