0

我有一个Dictionary<string, object>正在使用 NEST 2.0 库插入到 ElasticSearch 2.0 中。

默认文档名称是Dictionary'2. 我不知道为什么 NEST 选择这个名字,但我想要更明智的名字,比如“ DataRecord

如何设置文档名称?

第二种选择是创建一个空的包装类,但这似乎有点矫枉过正

4

1 回答 1

1

我认为最简单的方法是在ConnectionSettings.

var settings = new ConnectionSettings()
    .DefaultIndex(indexName)
    .MapDefaultTypeNames(dictionary => dictionary.Add(typeof(Dictionary<string,object>), "yourTypeName"))
    .DisableDirectStreaming()
    .PrettyJson();

var client = new ElasticClient(settings);

使用这种方法,您不必在索引文档或搜索时为输入类型名称而烦恼。

如果您需要对流程进行更多“控制”,您可以在调用 elasticsearch 时输入类型参数,但您必须在所有地方记住此参数。

var indexResponse = client.Index(new Dictionary<string, object>
{
    {"asd", 1}
}, descriptor => descriptor.Type("yourTypeName"));
于 2016-03-16T19:23:00.620 回答