在 Nest 5.5.0 中为 属性 设置 not_analyzed

Setting not_analyzed for a property in Nest 5.5.0

我尝试通过 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);

和项目 class:

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

这种初始化方式在我通过 Postman 调用 index/_mapping REST 后创建了某种奇怪的映射。有正常的 "mappings" 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
                                                        }
 (...)

要在 Elasticsearch 5.0+ 中设置未分析的字符串字段,您应该使用 keyword type,并在索引创建时使用 CreateIndex() 或在发送第一个文档之前传递映射使用 Map<T>() 到索引。在你的情况下,我认为你正在寻找类似

的东西
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 属性 也应该标记为关键字类型。