我在 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 倍。(每个文档大小都非常相似)
有任何想法吗?谢谢