public IActionResult List(PageListParam <SystemLogListParam> pageListParam) { var listParam = pageListParam.Params; var uris = new[] { new Uri("http://192.168.20.81:9200") }; using (var connectionPool = new SniffingConnectionPool(uris)) { using (var settings = new ConnectionSettings(connectionPool).DefaultIndex("chengongtestdb")) { settings.DeadTimeout(TimeSpan.FromMinutes(1)); settings.MaxRetryTimeout(TimeSpan.FromMinutes(1)); settings.ConnectionLimit(100); var client = new ElasticClient(settings); var qwe = client.Search <object>(a => a.AllIndices() .AllTypes().From(pageListParam.Limit * (pageListParam.Page - 1)) .Size(pageListParam.Limit).Query(q => q.Match(b => b.Field("_all").Query(listParam.Content)))); var documents = qwe.Hits.Select(a => new SystemLogList { Content = a.Source.ToJson(), Index = a.Index, Type = a.Type }).ToList(); return(PageListResult(new PageListResult(documents, (int)((SearchResponse <object>)qwe).Total))); } } }
private ConnectionSettings GetElasticSearchConnectionSettings(string indexName, int timeOut = 60000, int?connectionLimit = null) { var esUrl = GetConfigValue("ESConnection"); var settings = new ConnectionSettings(new Uri(esUrl)) .DefaultIndex(indexName) .DisableAutomaticProxyDetection(false) .RequestTimeout(TimeSpan.FromMilliseconds(timeOut)) .SniffLifeSpan(null) //.OnRequestCompleted(call => //{ // // log out the request and the request body, if one exists for the type of request // if (call.RequestBodyInBytes != null) // { // //logger.Debug($"{call.HttpMethod}\t{call.Uri}\t" + // // $"{Encoding.UTF8.GetString(call.RequestBodyInBytes)}"); // } // else // { // //logger.Debug($"{call.HttpMethod}\t{call.Uri}\t"); // } //}) ; if (System.Diagnostics.Debugger.IsAttached || GetConfigValue("ESDebugDataEnabled") == "true") { settings = settings.DisableDirectStreaming(); } if (connectionLimit.HasValue) { settings = settings.ConnectionLimit(connectionLimit.Value); } return(settings); }
public static ConnectionSettings GetElasticSearchConnectionSettings(string indexName, int timeOut = 60000, int?connectionLimit = null) { string esUrl = Devmasters.Core.Util.Config.GetConfigValue("ESConnection"); //var singlePool = new Elasticsearch.Net.SingleNodeConnectionPool(new Uri(esUrl)); var pool = new Elasticsearch.Net.StaticConnectionPool(esUrl .Split(';') .Where(m => !string.IsNullOrWhiteSpace(m)) .Select(u => new Uri(u)) ); //var pool = new Elasticsearch.Net.SniffingConnectionPool(esUrl // .Split(';') // .Where(m=>!string.IsNullOrWhiteSpace(m)) // .Select(u => new Uri(u))); var settings = new ConnectionSettings(pool) .DefaultIndex(indexName) .DisableAutomaticProxyDetection(false) .RequestTimeout(TimeSpan.FromMilliseconds(timeOut)) .SniffLifeSpan(null) .OnRequestCompleted(call => { // log out the request and the request body, if one exists for the type of request if (call.RequestBodyInBytes != null) { ESTraceLogger.Debug($"{call.HttpMethod}\t{call.Uri}\t" + $"{Encoding.UTF8.GetString(call.RequestBodyInBytes)}"); } else { ESTraceLogger.Debug($"{call.HttpMethod}\t{call.Uri}\t"); } }) ; if (System.Diagnostics.Debugger.IsAttached || ESTraceLoggerExists || Devmasters.Core.Util.Config.GetConfigValue("ESDebugDataEnabled") == "true") { settings = settings.DisableDirectStreaming(); } if (connectionLimit.HasValue) { settings = settings.ConnectionLimit(connectionLimit.Value); } //.ConnectionLimit(connectionLimit) //.MaximumRetries(2) //.SetProxy(new Uri("http://localhost.fiddler:8888"), "", "") #if DEBUG //settings = settings.; #endif return(settings); }
/// <summary> /// 获取Es链接设置 /// </summary> /// <returns></returns> public ConnectionSettings GetSettings() { var urls = EsHttpAddress.Split(';').Select(s => new Uri(s)); //链接池 var pool = new StaticConnectionPool(urls); var settings = new ConnectionSettings(pool).DefaultIndex(EsDefaultIndex); //网络代理 if (!string.IsNullOrEmpty(EsNetworkProxy)) { settings.Proxy(new Uri(EsNetworkProxy), "", ""); } //连接数限制 if (EsConnectionLimit > 0) { settings.ConnectionLimit(EsConnectionLimit); } return(settings); }
/// <summary> /// 获取Es链接设置 /// </summary> /// <returns></returns> private static ConnectionSettings GetSettings(ElasticSearchSetting setting) { var urls = setting.EsHttpAddress.Split(';').Select(s => new Uri(s)); //链接池 var pool = new StaticConnectionPool(urls); var settings = new ConnectionSettings(pool).DefaultIndex(setting.EsDefaultIndex); if (!string.IsNullOrEmpty(setting.UserName) && !string.IsNullOrEmpty(setting.Password)) { settings.BasicAuthentication(setting.UserName, setting.Password); } //网络代理 if (!string.IsNullOrEmpty(setting.EsNetworkProxy)) { settings.Proxy(new Uri(setting.EsNetworkProxy), "", ""); } //连接数限制 if (setting.EsConnectionLimit > 0) { settings.ConnectionLimit(setting.EsConnectionLimit); } return(settings); }