c#-ElasticSearch-Nest v7.x“忽略= true”不适用于字段

问题描述 投票:1回答:1

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

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

这里是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
                        }
                    }
                },
            }   
        }
    }
}

UPDATE !!用于映射的Nest代码如下

var createIndexResponse = _connectionToEs.EsClient().Indices.Create("cweeindex", c => c
                                                    .Map<EsStandardContract>(m => m.AutoMap())
                                                );

[请让我做错了!!在此先感谢。

c# elasticsearch nest querydsl
1个回答
0
投票

这看起来像是从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; }
© www.soinside.com 2019 - 2024. All rights reserved.