using Elasticsearch.Net; using Nest; using System; using System.Linq; namespace Sanhe.Abp.Elasticsearch { public class AbpElasticsearchOptions { /// /// 字段名称 是否为 camelCase 格式。 /// 如果为true, 在ES中为 camelCase。 /// 如果为false,在ES中为 CamelCase。 /// 默认:false。 /// public bool FieldCamelCase { get; set; } /// /// Ensures the response bytes are always available on the /// public bool DisableDirectStreaming { get; set; } /// /// ES端点,多个端点以,或;分隔 /// public string NodeUris { get; set; } /// /// 最大连接数 /// public int ConnectionLimit { get; set; } /// /// 连接用户名 /// public string UserName { get; set; } /// /// 用户密码 /// public string Password { get; set; } /// /// 连接超时时间 /// public TimeSpan ConnectionTimeout { get; set; } /// /// /// public IConnection Connection { get; set; } /// /// /// 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; } } }