我想将B字段存储在Elasticsearch中,但不要索引。当我搜索"Nash"
时,我不想在B字段中搜索。因此,B字段未在 flex 索引中。
[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 Attributes
显示不应对该字段建立索引。
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/attribute-mapping.html
在您的示例中,可能是这样的:
[ElasticsearchType(Name = "ES6")]
public class ES6
{
[Text]
public string A { get; set; }
[Keyword(Index = false)]
public string B { get; set; }
}
将其设置为
keyword
将确保未对其进行分析,而将Index = false
设置为将告诉Elastic不要为其编制索引。
关于c# - C#NEST ElasticSearch属性存储但不包含索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52944601/