【发布时间】:2018-01-16 07:50:59
【问题描述】:
我在 Windows 上的 ASP.NET API (.NET 4.6) 上使用 Elasticsearch.NET (5.6),并尝试发布到 AWS 上托管的 elasticsearch(我尝试了 5.1.1 和 6,两者的行为相同)。
我有以下代码将文档批量索引到 Elasticsearch。图片多次调用以下代码块:
var node = new System.Uri(restEndPoint);
var settings = new ConnectionSettings(node);
var lowlevelClient = new ElasticLowLevelClient(settings);
var index = indexStart + indexSuffix;
var items = new List<object>(list.Count() * 2);
foreach (var conn in list)
{
items.Add(new { index = new { _index = index, _type = "doc", _id = getId(conn) } });
items.Add(conn);
}
try
{
var indexResponse = lowlevelClient.Bulk<Stream>(items);
if (indexResponse.HttpStatusCode != 200)
{
throw new Exception(indexResponse.DebugInformation);
}
return indexResponse.HttpStatusCode;
}
catch (Exception ex)
{
ExceptionManager.LogException(ex, "Cannot publish to ES");
return null;
}
运行正常,可以将文档发布到Elasticsearch,但只能运行80次,80次后总是报异常:
# OriginalException: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Users\russ\source\elasticsearch-net-5.x\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 148
最有趣的部分是:我尝试将批量大小更改为 200 或 30,结果是 16000 和 2400,这意味着两者都以 80 倍结束。 (每个文档大小都非常相似)
有什么想法吗?谢谢
【问题讨论】:
-
您尝试发送的一个请求有多大,即列表中有多少项,一个请求中的总字节数是多少?
-
另外,您使用的是哪个版本的 NEST?您的目标是什么版本的 Elasticsearch?什么操作系统和 .NET 框架版本?
-
@RussCam 感谢您的提问,我刚刚更新了我的问题。
-
你知道为什么 lib 在 80 次批量操作后就开始超时了吗?
-
我怀疑从每个调用返回的
Stream没有被处理掉,并且您正在达到打开并发连接数的默认连接限制(80 个):github.com/elastic/elasticsearch-net/blob/master/src/…
标签: elasticsearch nest elasticsearch.net