NEST指定id
Posted chenyishi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NEST指定id相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章