c# - ElasticSearch:为什么索引中的所有文本字段都具有关键字类型?

标签 c# elasticsearch nest

我将NEST与具有属性的类配对使用来推送新文档。
这是我定义类的方法:

public class PatientNestModel
    {
        [Text]
        public string FirstName { get; set; }
        [Text]
        public string LastName { get; set; }
        [Text]
        public string MiddleName { get; set; }
        [Date(Format = "dd-MM-yyyy")]
        public DateTime BirthdayDate { get; set; }
        [Keyword]
        public string Gender { get; set; }
        [Text]
        public string Phone { get; set; }
        [Nested]
        public List<AdditionalContact> AdditionalContacts { get; set; }
        [Boolean]
        public bool Active { get; set; }
    }

这是我的推送方式:
var response = _esClient.Index(model, idx => idx.Index("patients_esindex"));

但是,然后我的索引元数据看起来带有关键字类型。
{
    "state": "open",
    "settings": {
        "index": {
            "creation_date": "1543806292300",
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "uuid": "3_J5ck_CTaCLEdhIbCC0ZQ",
            "version": {
                "created": "6030199"
            },
            "provided_name": "patients_esindex"
        }
    },
    "mappings": {
        "patientnestmodel": {
            "properties": {
                "firstName": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                "lastName": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                "gender": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                "birthdayDate": {
                    "type": "date"
                },
                "phone": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                },
                "active": {
                    "type": "boolean"
                },
                "middleName": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    },
    "aliases": [],
    "primary_terms": {
        "0": 1,
        "1": 1,
        "2": 1,
        "3": 1,
        "4": 1
    },
    "in_sync_allocations": {
        "0": [
            "DCbu6-HvQT2ziCzhFZKU6A"
        ],
        "1": [
            "9SGADbBfSWuH7AanJUGgRA"
        ],
        "2": [
            "dPmhURTzTVWFV4z6Fh8ctw"
        ],
        "3": [
            "RHX67o0QQsueD6G67IXAkg"
        ],
        "4": [
            "aoBxi-i8Q1aVSeq1tT69Lw"
        ]
    }
}

但是,只有当我将术语与.keyword一起使用时,我才能通过文本搜索找到所需的文档

我做错了什么?

最佳答案

从ES 5.0开始,字符串字段已分为两种新类型:应该用于全文搜索的文本和应该用于关键字搜索的关键字。

https://www.elastic.co/blog/strings-are-dead-long-live-strings

关于c# - ElasticSearch:为什么索引中的所有文本字段都具有关键字类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53586989/

相关文章:

elasticsearch - 如何使用通配符从 Elasticsearch 查询字符串中找到真​​实分数?

c# - C# Elasticsearch 查询,匹配多个查询

c# - 使用 NEST 创建自定义 token 过滤器

c# - C 与 C# 或 JAVA 中的 char 有什么区别

c# - 实现个人用户帐户和 Azure AD 身份验证

c# - Entity Framework 代码第一个子导航属性 null

ElasticSearch 索引文档未立即返回

elasticsearch - 当 `target` 不是 `source` 子字段时,ECS 兼容模式需要 `ip`,例如。 [客户端][ip]

c# - 如何检查字符串的前两个值

elasticsearch - 是否可以使用 Kibana 4 创建 XY(又名散点图)图?