elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

C#NEST Elastics搜索属性存储,但不搜索索引

C#NEST Elastics搜索属性存储,但不搜索索引,c#,elasticsearch,nest,C#,elasticsearch,Nest,我希望B字段存储在Elasticsearch中,但从不索引。当我搜索“Nash”时,我不想在B字段中搜索。所以B场在弹性体中没有索引 [ElasticsearchType(Name = "ES6")] public class ES6 { public string A { get; set; } public string B { get; set; } } elasticClient.IndexDocument(ne

我希望B字段存储在Elasticsearch中,但从不索引。当我搜索
“Nash”
时,我不想在B字段中搜索。所以B场在弹性体中没有索引

    [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" });

如果希望某个字段不被索引,可以使用NEST
属性
显示该字段不应被索引

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

[ElasticsearchType(Name = "ES6")]
public class ES6
{
    [Text]
    public string A { get; set; }

    [Keyword(Index = false)]
    public string B { get; set; }
}
将其设置为
keyword
将确保未对其进行分析,并且设置
Index=false
将告诉Elastic不要对其进行索引