You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.9 KiB
94 lines
2.9 KiB
using Elasticsearch.Net; |
|
using Nest; |
|
using System; |
|
using System.Linq; |
|
|
|
namespace Sanhe.Abp.Elasticsearch |
|
{ |
|
public class AbpElasticsearchOptions |
|
{ |
|
/// <summary> |
|
/// 字段名称 是否为 camelCase 格式。 |
|
/// 如果为true, 在ES中为 camelCase。 |
|
/// 如果为false,在ES中为 CamelCase。 |
|
/// 默认:false。 |
|
/// </summary> |
|
public bool FieldCamelCase { get; set; } |
|
/// <summary> |
|
/// Ensures the response bytes are always available on the <see cref="ElasticsearchResponse{T}" /> |
|
/// </summary> |
|
public bool DisableDirectStreaming { get; set; } |
|
/// <summary> |
|
/// ES端点,多个端点以,或;分隔 |
|
/// </summary> |
|
public string NodeUris { get; set; } |
|
/// <summary> |
|
/// 最大连接数 |
|
/// </summary> |
|
public int ConnectionLimit { get; set; } |
|
/// <summary> |
|
/// 连接用户名 |
|
/// </summary> |
|
public string UserName { get; set; } |
|
/// <summary> |
|
/// 用户密码 |
|
/// </summary> |
|
public string Password { get; set; } |
|
/// <summary> |
|
/// 连接超时时间 |
|
/// </summary> |
|
public TimeSpan ConnectionTimeout { get; set; } |
|
/// <summary> |
|
/// |
|
/// </summary> |
|
public IConnection Connection { get; set; } |
|
/// <summary> |
|
/// |
|
/// </summary> |
|
public ConnectionSettings.SourceSerializerFactory SerializerFactory { get; set; } |
|
|
|
public AbpElasticsearchOptions() |
|
{ |
|
ConnectionLimit = ConnectionConfiguration.DefaultConnectionLimit; |
|
ConnectionTimeout = ConnectionConfiguration.DefaultTimeout; |
|
} |
|
|
|
internal IConnectionSettingsValues CreateConfiguration() |
|
{ |
|
IConnectionPool connectionPool; |
|
var nodes = NodeUris |
|
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) |
|
.Select(uriString => new Uri(uriString)); |
|
|
|
if (nodes.Count() == 1) |
|
{ |
|
connectionPool = new SingleNodeConnectionPool(nodes.First()); |
|
} |
|
else |
|
{ |
|
connectionPool = new StaticConnectionPool(nodes); |
|
} |
|
|
|
var configuration = new ConnectionSettings( |
|
connectionPool, |
|
Connection, |
|
SerializerFactory) |
|
.ConnectionLimit(ConnectionLimit) |
|
.RequestTimeout(ConnectionTimeout); |
|
|
|
if (!FieldCamelCase) |
|
{ |
|
configuration.DefaultFieldNameInferrer((name) => name); |
|
} |
|
|
|
if (UserName.IsNullOrWhiteSpace()) |
|
{ |
|
configuration.BasicAuthentication(UserName, Password); |
|
} |
|
|
|
configuration.DisableDirectStreaming(DisableDirectStreaming); |
|
|
|
return configuration; |
|
} |
|
} |
|
}
|
|
|