문제

I need to get result below with NEST (Elastic Search .NET client)

"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
        }
    }
}

I have done so far

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

which gets me

"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"
        }
    }
}

so, any idea how to

  1. add "index_options": "docs" (I found IndexOptions.docs but it is not valid as Attribute)
  2. change sort to untouched
도움이 되었습니까?

해결책

The attribute based mapping only gets you so far. It's good enough if you only need to change names and set simple properties.

The recommended approach is to use client.MapFluent()

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

For an example how to set index_options

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

To see how you can create your own multi_field mapping.

You can even combine both approaches:

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

client.Map() and client.MapFromAttributes() will most likely be removed at some point.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top