如何在Elasticsearch Nest中添加条件属性以创建索引?

问题描述 投票:0回答:1

我想在某些条件下创建索引,例如使用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)));
            }

但是我收到以下错误,您能指导我如何做到这一点。

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

elasticsearch nest elasticsearch-7
1个回答
0
投票

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

_con.client.Indices.Create(indexname, 
    index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0)).Map(m=>m.Properties(ps => p)));

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.