【问题标题】:Setting not_analyzed for a property in Nest 5.5.0在 Nest 5.5.0 中为属性设置 not_analyzed
【发布时间】:2018-01-03 06:09:16
【问题描述】:

我尝试通过 Nest 5.5.0 设置“not_analyzed”索引类型,但我不知道该怎么做。

我的初始化:

var map = new CreateIndexDescriptor(INDEX_NAME)
     .Mappings(ms => ms.Map<Project>(m => m.AutoMap()));

var connectionSettings = new ConnectionSettings().DefaultIndex(INDEX_NAME);
_client = new ElasticClient(connectionSettings);

_client.Index(map);

还有项目类:

[ElasticsearchType(Name = "project")]
public class Project
{
    public Guid Id { get; set; }
    [Text(Analyzer = "not_analyzed")]
    public string OwnerIdCode { get; set; }
}

在我通过 Postman 调用 index/_mapping REST 之后,这种 init 方式会创建某种奇怪的映射。有普通的“映射”JSON 部分,就在“createindexdescriptor”下方,数据几乎相同。

"examinations4": {
    "mappings": {
        "project": {
            (...)
        },
        "createindexdescriptor": {
            "properties": {
                "mappings": {
                    "properties": {
                        "project": {
                            "properties": {
                                "properties": {
                                    "properties": {
                                        "id": {
                                            "properties": {
                                                "type": {
                                                    "type": "text",
                                                    "fields": {
                                                        "keyword": {
                                                            "type": "keyword",
                                                            "ignore_above": 256
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        "ownerIdCode": {
                                            "properties": {
                                                "analyzer": {
                                                    "type": "text",
                                                    "fields": {
                                                        "keyword": {
                                                            "type": "keyword",
                                                            "ignore_above": 256
                                                        }
                                                    }
                                                },
                                                "type": {
                                                    "type": "text",
                                                    "fields": {
                                                        "keyword": {
                                                            "type": "keyword",
                                                            "ignore_above": 256
                                                        }
 (...)

【问题讨论】:

    标签: c# elasticsearch mapping nest elasticsearch-analyzers


    【解决方案1】:

    要在 Elasticsearch 5.0+ 中设置未分析的字符串字段,您应该使用 keyword type,并在创建索引时使用 CreateIndex() 或在第一个文档发送到索引之前使用 @987654324 传递映射@。就您而言,我认为您正在寻找类似的东西

    void Main()
    {
        var connectionSettings = new ConnectionSettings()
            .DefaultIndex("default-index");
    
        var client = new ElasticClient(connectionSettings);
    
        client.CreateIndex("projects", c => c
            .Mappings(m => m
                .Map<Project>(mm => mm
                    .AutoMap()
                )
            )
        );
    }
    
    [ElasticsearchType(Name = "project")]
    public class Project
    {
        [Keyword]
        public Guid Id { get; set; }
    
        [Keyword]
        public string OwnerIdCode { get; set; }
    }
    

    我认为Id 属性也应该标记为关键字类型。

    【讨论】:

    • 非常感谢!我只是无法弄清楚如何使用“入门”文档来处理初始化。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多