我要求在写入 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);
}