0

我需要使用 NEST(Elastic Search .NET 客户端)获得以下结果

"detailVal": {
    "name": "detailVal",
    "type": "multi_field",
    "fields": {
        "detailVal": {
            "type": "string"
        },
        "untouched": {               // <== FOCUS 2
            "type": "string",
            "index": "not_analyzed",
            "omit_norms": true,
            "include_in_all": false,
            "index_options": "docs"  // <== FOCUS 1
        }
    }
}

到目前为止我已经做了

    [ElasticProperty(OmitNorms = true, Index = FieldIndexOption.not_analyzed, IncludeInAll = false, AddSortField = true)]
    public string DetailVal { get; set; }

这让我

"detailVal": {
    "name": "detailVal",
    "type": "multi_field",
    "fields": {
        "detailVal": {
            "type": "string",
            "index": "not_analyzed",
            "omit_norms": true,
            "include_in_all": false
        },
        "sort": {                    // <== FOCUS 2
            "type": "string",
            "index": "not_analyzed"
        }
    }
}

所以,任何想法如何

  1. 添加“index_options”:“docs” (我找到了IndexOptions.docs,但它作为属性无效)
  2. 排序更改为未触及
4

1 回答 1

0

到目前为止,基于属性的映射只能帮助您。如果您只需要更改名称并设置简单的属性就足够了。

推荐的方法是使用client.MapFluent()

https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs#L129

例如如何设置index_options

第 208 行: https ://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Map/FluentMappingFullExampleTests.cs#L208

了解如何创建自己的 multi_field 映射。

你甚至可以结合这两种方法:

client.MapFluent<MyType>(m=>m
     .MapFromAttributes()
     //Map what you can't with attributes here
);

client.Map()并且client.MapFromAttributes()很可能会在某个时候被删除。

于 2014-01-07T17:21:07.020 回答