码迷,mamicode.com
首页 > 其他好文 > 详细

NEST指定id

时间:2019-09-18 11:25:22      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:guid   arc   uri   cse   nbsp   nes   str   cti   ltm   

1.默认以Id属性为Id,无Id属性则自动生成

 

2.可通过属性标签指定Id

[ElasticsearchType(IdProperty = nameof(last_name))]
    public class employee
    {
        public Guid Id { get; set; } = Guid.NewGuid();
        public string first_name { get; set; }
        public string last_name { get; set; }
        public int age { get; set; }
        public string about { get; set; }
        public List<string> interests { get; set; }

        public employeedto dto { get; set; }
    }


    public class employeedto
    {
        public Guid Id { get; set; }
    }

  

3.初始化client时指定

            var node = new Uri("http://192.168.60.222:9200/");
            var settings = new ConnectionSettings(node)
                .DefaultIndex("employee")
                .DefaultMappingFor<employee>(x => x.IdProperty(p => p.last_name));
            client = new ElasticClient(settings);

  

 

4.索引时指定

        public IIndexResponse IndexDoc(employee doc)
        {
            return client.Index(doc,x=>x.Id(doc.last_name));
        }

  

 

NEST指定id

标签:guid   arc   uri   cse   nbsp   nes   str   cti   ltm   

原文地址:https://www.cnblogs.com/chenyishi/p/11539888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!