@ -1,8 +1,9 @@
using Elasticsearch.Net ;
using Nes t;
using Elastic.Clients.Elastic search ;
using Elastic.Transpor t;
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
/// </summary>
public bool FieldCamelCase { get ; set ; }
/// <summary>
/// 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.
/// </summary>
public bool DisableDirectStreaming { get ; set ; }
public string NodeUris { get ; set ; }
public int ConnectionLimit { get ; set ; }
/// <summary>
/// `Base64ApiKey` for Elastic Cloud style encoded api keys
/// </summary>
public string? Base64ApiKey { get ; set ; }
/// <summary>
/// `ApiKey` for simple secret token
/// </summary>
public string? ApiKey { get ; set ; }
/// <summary>
/// `UserName` for basic authentication
/// </summary>
public string? UserName { get ; set ; }
/// <summary>
/// `Password` for basic authentication
/// </summary>
public string? Password { get ; set ; }
public TimeSpan ConnectionTimeout { get ; set ; }
public IConnection Connection { get ; set ; }
public ConnectionSettings . SourceSerializerFactory SerializerFactory { get ; set ; }
/// <summary>
/// Default: 60s
/// </summary>
public TimeSpan RequestTimeout { get ; set ; }
/// <summary>
///
/// </summary>
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 ( 6 0 ) ;
}
internal IConnectionSettingsValues CreateConfiguration ( )
internal IElasticsearchClientSettings CreateClientSettings ( )
{
IConnectionPool connection Pool;
NodePool node Pool;
IEnumerable < Uri > nodes = NodeUris
. Split ( new [ ] { ',' , ';' } , StringSplitOptions . RemoveEmptyEntries )
. Select ( uriString = > new Uri ( uriString ) ) ;
if ( nodes . Count ( ) = = 1 )
{
connection Pool = new SingleNodeConnection Pool ( nodes . First ( ) ) ;
node Pool = new SingleNodePool ( nodes . First ( ) ) ;
}
else
{
connectionPool = new StaticConnection Pool( nodes ) ;
nodePool = new StaticNode Pool( nodes ) ;
}
var configuration = new Connection Settings (
connection Pool,
Connection ,
var clientSettings = new ElasticsearchClient Settings (
node Pool,
RequestInvoker ,
SerializerFactory )
. ConnectionLimit ( ConnectionLimit )
. RequestTimeout ( Connection Timeout) ;
. RequestTimeout ( Request Timeout) ;
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 ;
}
}
}