C# NEST ElasticSearch 属性 存储但不索引
C# NEST ElastichSearch property store but not index
我想将 B 字段存储在 Elasticsearch 中但不索引。当我搜索 "Nash"
时,我不想在 B 字段中搜索。所以B字段在elastic中是没有索引的。
[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 不要对其进行索引。
我想将 B 字段存储在 Elasticsearch 中但不索引。当我搜索 "Nash"
时,我不想在 B 字段中搜索。所以B字段在elastic中是没有索引的。
[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 不要对其进行索引。