7

我试图通过 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
                                                        }
 (...)
4

1 回答 1

12

要在 Elasticsearch 5.0+ 中设置未分析的字符串字段,您应该使用keywordtypeCreateIndex() ,并在创建索引时使用或在第一个文档发送到索引之前使用传递映射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属性也应该标记为关键字类型。

于 2017-07-29T01:30:18.903 回答