AddSortField in nest 2 upgrade

冷暖自知 提交于 2019-12-08 11:19:04

问题


I used to use the add-sort-field=true as an attribute to a property, but with the new nest I can't find the equivalent. Where is it?

Thanks.


回答1:


Looks like it has been accidently removed from NEST 2.x. I couldn't find any trace why. Feel free to ask this question if you think it was useful in your case. Link to the NEST github.

As far I as I understand, property was creating fieldname.sort field which was not_analyzed.

For time being you can handle this by explicit creating field. Unfortunately you won't be able to do this with attribute-based mapping, but you can successfully mix two techniques.

var createIndexResponse = client.CreateIndex(indexName, descriptor => descriptor
    .Mappings(map => map
        .Map<Document>(m => m
            .AutoMap()
            .Properties(ps => ps
                .String(s => s
                    .Name(n => n.Country)
                    .Fields(f => f
                        .String(ss => ss.Name(n => n.Country.Suffix("sort")).NotAnalyzed()))))
        )));


public class Document
{
    public int Id { get; set; } 
    [String(Name = "c")]
    public string Country { get; set; }
}

Hope it helps you.



来源:https://stackoverflow.com/questions/36425486/addsortfield-in-nest-2-upgrade

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!