elasticsearch - 如何在 elasticsearch 嵌套中添加条件属性以创建索引?
问题描述
我想创建具有某些条件的索引,例如使用 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>>'
解决方案
您快到了,只需将Properties
部分更改为m.Properties(p => ps)
.
_con.client.Indices.Create(indexname,
index => index.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0)).Map(m=>m.Properties(p => ps)));
希望有帮助。
推荐阅读
- kibana - 如何从 kibana 过滤器的下拉列表中删除标签
- json - 在 JSON 中生成“|”到 YML
- html - 右侧按钮下方的文字
- java - itext 7(java)将新页面上的图像添加到现有pdf文档的末尾
- graphql - Hasura 查询的工作方式类似于 SQL 内连接
- ruby - 什么是 << 在 ruby 中代表整数
- git - git mergetool 在cherry-pick 中显示了许多不相关的更改
- php - How to Filter Content passed to a WordPress Shortcode
- c++ - Using auto to a variable assigned ot a function that return const ref
- python - how do I loop backward for 4 values and do it for next values in a list?