首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#嵌套ElastichSearch属性存储而不是索引

C#嵌套ElastichSearch属性存储而不是索引
EN

Stack Overflow用户
提问于 2018-10-23 08:34:30
回答 1查看 935关注 0票数 1

我希望B字段存储在Elasticsearch中,但绝不索引。当我搜索"Nash"时,我不想在B字段中搜索。所以B字段不是用弹性索引的。

代码语言:javascript
复制
    [ElasticsearchType(Name = "ES6")]
    public class ES6
    {
        public string A { get; set; }

        public string B { get; set; }
    }

    elasticClient.IndexDocument(new ES6 { A = "John", B = "Nash" });

    elasticClient.IndexDocument(new ES6 { A = "Nash", B = "John" });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-23 13:19:55

如果您希望有一个字段不被索引,您可以使用NEST Attributes来显示字段不应该被索引。

https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html

在您的示例中,可能是这样的:

代码语言:javascript
复制
[ElasticsearchType(Name = "ES6")]
public class ES6
{
    [Text]
    public string A { get; set; }

    [Keyword(Index = false)]
    public string B { get; set; }
}

将其设置为keyword将确保不对其进行分析,而设置Index = false将告诉弹性不对其进行索引。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52944601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档