gpt4 book ai didi

elasticsearch - NEST:更新源过滤器

转载 作者:行者123 更新时间:2023-12-02 22:30:01 26 4
gpt4 key购买 nike

我有一个将查询作为参数的方法,例如:

public ISearchResponse<Object> SearchComponent(SearchDescriptor<Object> query)
{
...
}

在此查询中,我想添加一个源过滤器,例如:

public ISearchResponse<Object> SearchComponent(SearchDescriptor<Object> query)
{
query = query.Source(sf =>
sf.Exclude(e => e
.Field("SomeField")
));
...
}

但是如果查询已经有源过滤器会怎样呢?这个过滤器会覆盖那个过滤器吗?如何更新现有的查询源过滤器?

最佳答案

这似乎可行,但它不是最漂亮的解决方案。谁能想出更好的选择?

public ISearchResponse<Object> SearchComponent(ISearchRequest query)
{
var excludeFields = new List<string>();
excludeFields.Add("SomeField");

if (query.Source == null)
{
query.Source = new SourceFilter {Include = "*", Exclude = excludeFields.ToArray()};
}
else if (query.Source.Exclude == null)
{
query.Source.Exclude = excludeFields.ToArray();
}
else
{
query.Source.Exclude.And(excludeFields.ToArray());
}
...
}

关于elasticsearch - NEST:更新源过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44435169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com