public static void Add(IConnectionPool pool, string name) { if (name == null) { if (_client != null) { throw new Exception("esName:default ES Client exist"); } _client = new ElasticSearchClient(pool); } else { if (_clientList == null) { _clientList = new ConcurrentDictionary <string, ElasticSearchClient>(); } if (_clientList.Keys.Contains(name)) { throw new Exception($"esName:{name} ES Client exist"); } _clientList.TryAdd(name, new ElasticSearchClient(pool)); } }
public static IESQuery <TEntity> Create <TEntity>(string name = null) where TEntity : class { var esBuilder = new ESBuilderBase <TEntity>(); ElasticSearchClient client = null; if (name == null) { client = _client; } else { if (!_clientList.TryGetValue(name, out client)) { throw new NullReferenceException($"esName:{name} ES Client not exist"); } } if (client == null) { throw new NullReferenceException("ES Client not exist"); } var query = new ESQuery <TEntity>(esBuilder, client); return(query); }
public static IESStores <TEntity> CreateStore <TEntity>(string name = null) where TEntity : class { ElasticSearchClient client = null; if (name == null) { client = _client; } else { if (!_clientList.TryGetValue(name, out client)) { throw new NullReferenceException($"esName:{name} ES Client not exist"); } } if (client == null) { throw new NullReferenceException("ES Client not exist"); } var store = new ESStoreBase <TEntity>(client); return(store); }