c# - C#NEST ElasticSearch属性存储但不包含索引

标签 c# elasticsearch nest

我想将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/

相关文章:

c# - 计算Elasticsearch中的过滤数据(ElasticClient nest)

elasticsearch - 嵌套查询在 bool 中写入必须和应该

elasticsearch - GeoShape 不存储纬度/经度

c# - 带接口(interface)约束的泛型方法与带接口(interface)参数的方法的区别

c# - Windows 窗体中的套接字问题。更改选项卡控件时套接字停止回复

java - Elasticsearch 中的节点

elasticsearch - 在 Elasticsearch 中无法索引大于100MB的文件

elasticsearch - 数据操作的API命名约定

c# - 从 Web 应用程序使用 photoshop 文件

c# - 获取特定字符之间的字符串