asp.net - 如何向 NEST 添加多个字段?
问题描述
我使用通用和反射,所以主要问题是添加几个字段。当我将此代码与一个字段一起使用时,它可以,但是当我尝试以某种方式添加新字段时它不起作用:
public static ISearchResponse<T> PartSearch<T>(ElasticClient client, string query, List<string> fieldList = null, int from = 0, int size = 1) where T : class
{
if (client == null)
throw new ArgumentNullException();
if (String.IsNullOrEmpty(query))
throw new ArgumentNullException();
ISearchResponse<T> results;
if (fieldList == null)
{
results = client.Search<T>(q =>
q.Query(q =>
q.QueryString(qs => qs.Query(query))
).From(from).Size(size)
);
}
else
{
results = client.Search<T>(q =>
q.Query(q => q
.QueryString(qs =>
{
//This place where i try to add several fields
List<Field> fildArray = new List<Field>();
foreach (var arg in fieldList)
{
var fieldString = new Field(typeof(T).GetProperty(arg));
fildArray.Add(fieldString);
}
qs.Fields(f => f.Field(fildArray));
qs.Query(query);
return qs;
})
).From(from).Size(size)
);
}
return results;
}
解决方案
我使用 Lenient() 创建了一个示例,可以帮助您解决问题:
推荐阅读
- azure - 如何对开发团队创建的 Azure 分析服务进行 QA 测试
- java - 我的 RSA 解密不返回纯文本
- java - 在 LINKEDLIST 制作的 QUEUE 中用什么代替 NULL
- javascript - 在 Bootstrap 按钮上使用 JavaScript 模拟用户点击事件
- php - 即使闭包按值返回,如何将闭包的返回值通过引用分配给变量?
- jquery - “在jquery之前点击功能不起作用
- python - 如何阻止 Spyder 清除变量而不是执行我的 PyQt 脚本?
- r - 使用 stringr 进行 mutate 中的字符串操作
- ssl - 使用 Mailkit 连接到 Pop3 服务器时,每隔一次连接失败
- java - 区别 new LinkedList<>(new LinkedList<>()) 和 new LinkedList...,添加