elasticsearch 如何在elasticsearch嵌套中为索引创建添加条件属性?,elasticsearch,nest,elasticsearch-7,elasticsearch,Nest,Elasticsearch 7" /> elasticsearch 如何在elasticsearch嵌套中为索引创建添加条件属性?,elasticsearch,nest,elasticsearch-7,elasticsearch,Nest,Elasticsearch 7" />

elasticsearch 如何在elasticsearch嵌套中为索引创建添加条件属性?

elasticsearch 如何在elasticsearch嵌套中为索引创建添加条件属性?,elasticsearch,nest,elasticsearch-7,elasticsearch,Nest,Elasticsearch 7,我想用一些条件创建索引,比如使用querycontainer来添加条件过滤器 PropertiesDescriptor<object> ps = new PropertiesDescriptor<object>(); if (condition) { ps.Text(s => s.Name(name[1])); } if(condition

我想用一些条件创建索引,比如使用querycontainer来添加条件过滤器

PropertiesDescriptor<object> ps = new PropertiesDescriptor<object>();
            if (condition)
            {
                ps.Text(s => s.Name(name[1]));
            }
            if(condition)
            {
                ps.Number(s => s.Name(name[1]));
            }
            if (!_con.client.Indices.Exists(indexname).Exists)
            {
                var createIndexResponse = _con.client.Indices.Create(indexname, index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0))
                                                                                                .Map(m=>m.Properties(ps)));
            }
PropertiesDescriptor ps=新的PropertiesDescriptor();
如果(条件)
{
ps.Text(s=>s.Name(Name[1]);
}
如果(条件)
{
ps.Number(s=>s.Name(Name[1]);
}
如果(!\u con.client.index.Exists(indexname.Exists)
{
var createIndexResponse=_con.client.index.Create(indexname,index=>index.Settings(s=>s.NumberOfShards(1.NumberOfReplicas(0))
.Map(m=>m.Properties(ps));
}
但我收到以下错误,你能指导我如何做到这一点

cannot convert from 'Nest.PropertiesDescriptor<object>' to 'System.Func<Nest.PropertiesDescriptor<object>, Nest.IPromise<Nest.IProperties>>'

无法从“Nest.PropertiesDescriptor”转换为“System.Func”

您就快到了,只需将
属性
部分更改为
m.Properties(p=>ps)


希望这能有所帮助。

谢谢@Rob,但是你的答案中可能有一个错误,应该是
m.Properties(p=>ps)
而不是
m.Properties(ps=>p)
_con.client.Indices.Create(indexname, 
    index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0)).Map(m=>m.Properties(p => ps)));