gpt4 book ai didi

c# - 题-ElasticSearch-Nest v7.x “Ignore = true”在字段上不起作用

转载 作者:行者123 更新时间:2023-12-02 23:13:12 30 4
gpt4 key购买 nike

我正在尝试对POCO类中的某些字段进行索引,并将某些属性装饰为“忽略= true”,并且这些字段不应被索引,而应该被存储。我希望这些字段出现在搜索结果中,但不应作为索引。

我正在尝试对应索引的几个字段进行映射,并忽略所有其他具有“Ignore = true”作为Nest Library提供的装饰器的字段。

这是POCO类的示例。

[PropertyName("doi")]
public string Doi { get; set; }

[PropertyName("displayName")]
public string DisplayName { get; set; }

[PropertyName("itemType")]
public string ItemType { get; set; }

[PropertyName("fileReference")]
public string FileReference { get; set; }

[PropertyName("textFirstPage", Ignore = true)]
public string TextFirstPage { get; set; }

[PropertyName("textLastPage", Ignore = true)]
public string TextLastPage { get; set; }

[PropertyName("citationTitle", Ignore = true)]
public string CitationTitle { get; set; }

[PropertyName("translatedPublicationTitle", Ignore = true)]
public string TranslatedPublicationTitle { get; set; }

[PropertyName("alternatePublicationTitle", Ignore = true)]
public string AlternatePublicationTitle { get; set; }

[PropertyName("publicationSubTitle", Ignore = true)]
public string PublicationSubTitle { get; set; }

但是,当我尝试查看索引的映射时,POCO类中已提到的所有字段都会出现在“映射”中。
{
"cweeindex" : {
"mapping": {
"properties" : {
"doi": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"displayName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"fileReference": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"itemType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"citationTitle": {
"type": "boolean"
},
"publicationSubTitle": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"textFirstPage": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"textLastPage": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"translatedPublicationSubTitle": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"translatedPublicationTitle": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
}
}
}
}

更新!
映射的Nest代码如下
var createIndexResponse = _connectionToEs.EsClient().Indices.Create("cweeindex", c => c
.Map<EsStandardContract>(m => m.AutoMap())
);

拜托,让我我在做什么错!提前致谢。

最佳答案

这看起来像是从6.x到7.x的序列化所带来的回归。我已经打开an issue来解决。

现在,您可以使用Nest.IgnoreAttribute。例如

[PropertyName("doi")]
public string Doi { get; set; }

[PropertyName("displayName")]
public string DisplayName { get; set; }

[PropertyName("itemType")]
public string ItemType { get; set; }

[PropertyName("fileReference")]
public string FileReference { get; set; }

[Ignore]
public string TextFirstPage { get; set; }

[Ignore]
public string TextLastPage { get; set; }

[Ignore]
public string CitationTitle { get; set; }

[Ignore]
public string TranslatedPublicationTitle { get; set; }

[Ignore]
public string AlternatePublicationTitle { get; set; }

[Ignore]
public string PublicationSubTitle { get; set; }

关于c# - 题-ElasticSearch-Nest v7.x “Ignore = true”在字段上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58157898/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com