Nest 类型为isn';没有被使用?

Nest 类型为isn';没有被使用?,nest,Nest,我已经按照fluent API单元测试(FluentMappingFullExampleTests)中的示例为类型定义了编程映射,如下所示: \u client.Map(m=>m .类型(“mytype”) ... 然后,我通过如下调用将SomeType的实例添加到索引中 _client.Index<SomeType>(instance) \u客户端索引(实例) 但是,当我搜索一个实例时,我没有找到任何“mytype”的实例;相反,有一个“sometype”的实例,并且已经为该

我已经按照fluent API单元测试(FluentMappingFullExampleTests)中的示例为类型定义了编程映射,如下所示:

\u client.Map(m=>m
.类型(“mytype”)
...
然后,我通过如下调用将SomeType的实例添加到索引中

_client.Index<SomeType>(instance)
\u客户端索引(实例)
但是,当我搜索一个实例时,我没有找到任何“mytype”的实例;相反,有一个“sometype”的实例,并且已经为该“sometype”创建了一个新的类型映射。我希望在执行插入时会遵守PUT映射

我是否没有按照应该使用的方式使用PUT映射?不幸的是,单元测试没有演示往返,因此我不确定是否还有其他我应该做的事情


编辑:这里值得一提的是,我正在尝试实现100%的编程映射;类型上没有下一个属性。

在我的示例中,我能够处理您的用例:

//request url: http://localhost:9200/indexName
var indicesOperationResponse = client.CreateIndex(indexName);

//request url: http://localhost:9200/indexName/document2/_mapping
var response = client.Map<Document>(m => m
    .Type("document2")
    .Properties(p => p.String(s => s.Name(n => n.Name).Index(FieldIndexOption.NotAnalyzed))));

//request url: http://localhost:9200/indexName/document2/1
client.Index(new Document { Id = 1, Name = "test"});

client.Refresh();

//request url: http://localhost:9200/indexName/document2/_search
var searchResponse = client.Search<Document>(s => s.Query(q => q.MatchAll()));
希望这对你有帮助

更新

您的评论很有意义。您可以更改
ElasticClient
的类型名称推断,而不是使用
ElasticType

var uri = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(uri)
    .SetDefaultIndex(indexName)
    .MapDefaultTypeNames(d => d.Add(typeof(Document), "document2"))

var client = new ElasticClient(settings);
所以我们可以从
文档
类中删除属性

public class Document
{
    public int Id { get; set; }
    public string Name { get; set; }
}
我们也不需要在映射中指定类型别名:

var response = client.Map<Document>(m => m
    .Properties(p => p.String(s => s.Name(n => n.Name).Index(FieldIndexOption.NotAnalyzed))));
var-response=client.Map(m=>m
.Properties(p=>p.String(s=>s.Name(n=>n.Name).Index(FieldIndexOption.NotAnalyzed)));

是的,但是现在包含数据类型的程序集必须根据嵌套进行编译。使用编程映射的动机是允许我们在没有“知识”的情况下使用POCO对象所有的ElasticSearch,并让PUT映射处理所有的wireup。当您从类型中删除属性时会发生什么?啊哈!我本以为在映射中提供类型别名就可以实现这一点。我来试一试。快速问题:这种方法可以处理将多个数据类型别名为同一名称的情况吗?@AndyHopper是的。
public class Document
{
    public int Id { get; set; }
    public string Name { get; set; }
}
var response = client.Map<Document>(m => m
    .Properties(p => p.String(s => s.Name(n => n.Name).Index(FieldIndexOption.NotAnalyzed))));