【发布时间】:2016-08-05 01:47:29
【问题描述】:
我在 NEST 中的映射遇到了一些问题。
让我描述一下我的设置。
我正在将我的 ElasticClient 设置为我的 ioc 容器中的单例,如下所示:
ElasticClient client = new ElasticClient(settings);
client.CreateIndex("elasticsearch", c =>
c
.AddMapping<ProductDocument>(m => m.MapFromAttributes())
.AddMapping<PageDocument>(m => m.MapFromAttributes())
.AddMapping<MediaAsset>(ma => ma.MapFromAttributes()));
ProductDocument、PageDocument 和 MediaAsset 都继承自 ContentDocument 的属性。在这个问题中,我将专注于让 ProductDocument 工作。 (我省略了一些字段以节省您的眼睛)
public class ContentDocument
{
public string Id { get; set; }
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string DocumentKey { get; set; }
public string Title { get; set; }
public string Description { get; set; }
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string Language { get; set; }
public string Url { get; set; }
}
public class ProductDocument : ContentDocument
{
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public string GroupId { get; set; }
}
要索引文档,我只需将值放入属性中并使用
_elasticClient.Index(product);
但是,当我在 ElasticSearch 中检查映射时,我看到的是以下内容:
{
"elasticsearch" : {
"mappings" : {
"productdocument" : {
"properties" : {
...
"groupId" : {
"type" : "string"
},
"language" : {
"type" : "string"
}
}
}
}
}
我希望语言和 groupId 成为索引:“NotAnalyzed”。 我在这里做错了什么?
【问题讨论】:
-
嗯,很有趣。您是否尝试过不使用使用您的 IoC 容器的相同代码?我尝试在一个简单的控制台应用程序中复制您的代码,它按预期工作,即带注释的字段在索引映射中标记为
not_analyzed。可能会缩小问题所在。 -
您发布的代码看起来不错。您在创建索引调用后得到成功响应吗?紧随其后的索引映射是什么样的?
-
我一直在尝试解决这个问题,并且每次我请求 IElasticClient 时都将 ioc 容器设置为新容器,这似乎使问题发生的频率降低了。我会尝试一段时间,看看这是否完全解决了问题。 (我有一些客户端访问索引(使用旧代码),这可能会更改映射)
-
@CoolMcGrrr ElasticClient 作为单身人士是安全的
标签: elasticsearch nest