如何设置IndexOption = docs

时间:2014-01-07 17:04:21

标签: elasticsearch nest

我需要在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. 排序更改为未触动

1 个答案:

答案 0 :(得分: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

了解如何创建自己的多字段映射。

您甚至可以将两种方法结合起来:

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

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