nest - 使用 Nest 插入数据后的文档计数为 0
问题描述
我正在使用具有以下连接设置的 Nest:
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(connectionPool, new InMemoryConnection());
settings.DisableDirectStreaming(true); // needed to see good looking debug log on insert
settings.DefaultIndex(Index);
Client = new ElasticClient(settings);
new InMemoryConnection()
我希望使用 Nest 进行查询 - 在 Azure Cloud 函数中更改数据。
奇怪的是,调试日志看起来很有希望索引:
/*
var res = await Client.IndexManyAsync(response.Elements, Index); //
Console.WriteLine(res.DebugInformation);
*/
/*
var res = await Client.IndexAsync(response, i => i.Index(Index)); // Index = "data"
Console.WriteLine(res.DebugInformation); // <--
*/
并在插入后直接记录计数为 0:
// var anyDocs = await Client.CountAsync<OverpassElement>(c => c.Index(Index));
var anyDocs = await Client.CountAsync<OverpassElement>(c => c);
Console.WriteLine("count: " + anyDocs.Count);
..但是插入记录的整个json数据。
插入后为什么我不能数它(以便我可以在下一步中搜索)?
实际上我得到:
从 POST 上成功的 (200) 低级别调用构建的无效 NEST 响应:/data/_doc
0
并且在IndexResponse
插入中有项目。
数据看起来像包含 4221 个此类项目的Element
数组的以下部分:
{
"type": "relation",
"id": 8353694,
"timestamp": "2018-06-04T22:54:27Z",
"version": 1,
"changeset": 59551528,
"user": "asdf2",
"uid": 1416503,
"members": [
{
"type": "way",
"ref": 89956942,
"role": "from"
},
{
"type": "node",
"ref": 1042756547,
"role": "via"
},
{
"type": "way",
"ref": 89956938,
"role": "to"
}
],
"tags": {
"restriction": "no_left_turn",
"type": "restriction"
}
},
解决方案
ElasticSearch 与 NoSql 数据存储有许多相似之处。在这种情况下,默认情况下不保证“写后读”。当 index API 调用返回成功时,并不表示“该文档现在可以搜索”;这意味着“ElasticSearch 已接受您的文档,它将很快可供搜索”。ElasticSearch 默认使用最终一致性。
但是,这在测试期间可能很烦人。所以 ElasticSearch 有一个Refresh API,它基本上只是阻塞,直到所有已编入索引的文档都可用于搜索。我强烈建议您不要在生产中调用它;仅在测试代码中。
推荐阅读
- ruby-on-rails - ActiveResource“NoMethodError(nil:NilClass 的未定义方法‘路径’):”间歇性错误
- java - 覆盖java中的equals方法
- arangodb - 读取单个文档时出现“操作已取消”错误消息
- ada - 如何阻止控制台窗口立即关闭 | GNAT-全球定位系统
- macos - USB 设备没有出现在 macOS 下,甚至没有出现在 USB Prober
- artifactory - 从人工远程仓库下载大文件给出错误 - 意外 EOF
- excel - 将公式应用于单元格范围,然后粘贴值
- tableau-api - Tableau 为三个字段创建通用自定义素材箱
- javascript - 尝试从不同的函数中使用 Async 和 Await
- r - 使用 R 中更改的数据和变量名称运行相同的代码