c# - ElasticSearch:写入后立即查询数据

标签 c# elasticsearch nest elasticsearch-net

我要求在写入 ES 后能够立即按键读取数据。这可能吗?请注意 DataMap是一个键值对和 _id被路径到关键字段。

string v = "Foobar" + i;
string k = Security.Hash(Encoding.UTF8.GetBytes(v));

var data = new DataMap { Key = k, Value = v };
var index = _esclient.Index(data);

// fetch by k
var results = _esclient.Search<DataMap>(p => p
        .Size(1000)
        .Fields(f => f.Key, f => f.Value)
        .Query(q => q.Term("key", k))
        );

// Make sure the record is found
if (!results.Hits.Any())
{
    Console.WriteLine("{0} {1} not found", k, v);
}

最佳答案

是的。 GET API 为 realtime并将通过其 _id 返回一个文档收到后立即,即使索引尚未刷新。

请注意,向 Elasticsearch 提供唯一的 _id 可能会更简单,而不是让它为您生成一个。否则,您必须阅读索引操作的响应才能了解 _id的文件。

关于c# - ElasticSearch:写入后立即查询数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673978/

相关文章:

elasticsearch - 使用 NEST 进行多字段的正确方法

elasticsearch - 如何在术语查询中查询对象数组

c# - 使用一个 SQL 表的三向连接

c# - 在 C# 中将新结构分配给数组时会发生什么?

elasticsearch - 不同类型的Elasticsearch 7.6 “illegal_argument_exception”映射器[processes.pid],current_type [text],merged_type [long]

ruby-on-rails - 如何在 ruby​​ on rails 中获得 elasticsearch 性能优化

c# - 使ADO.NET(和EntityFramework)发布数据库

c# - Android(c2dm)推送通知错误

elasticsearch - Kibana可视化中的聚合之聚合

c# - 使用NEST使用ElasticSearch 2.x搜索多种类型时,如何得到混合结果?