gpt4 book ai didi

elasticsearch - Nest NamedFilters 需要 promise

转载 作者:行者123 更新时间:2023-12-03 02:10:37 24 4
gpt4 key购买 nike

我有简单的弹性请求:

var request4 =
_client.Search<T>(s => s
.Aggregations(aggs =>
aggs.Filters("FacetedSearch",
f => f
.NamedFilters(g =>
{
var namedFilters = new NamedFiltersContainer();


foreach (var facet in _facets)
{
namedFilters.Add(facet.Key,
Query<T>.Terms(p => new Nest.TermsQuery
{Field = facet.Key, Terms =
new[] {facet.Value}}));
}

return namedFilters;
})

但是,编译器需要 Nest.IPromise<Nest.INamedFiltersContainer>我还没有找到任何可以构造给定类型的 Promise 的构造函数。有没有办法将 NamedFiltersContainer 转换为 prmosie ?

最佳答案

您可以使用传递给委托(delegate)的参数来组成命名过滤器

var client = new ElasticClient();

var _facets = new Dictionary<string, string>
{
["foo"] = "bar",
["baz"] = "quux"
};

var request4 = client.Search<object>(s => s
.Aggregations(aggs =>
aggs.Filters("FacetedSearch", f => f
.NamedFilters(g =>
{
foreach (var facet in _facets)
{
g.Filter(facet.Key, Query<object>.Terms(p => p
.Field(facet.Key)
.Terms(new[] { facet.Value })
)
);
}

return g;
})
)
)
);
产量
{
"aggs": {
"FacetedSearch": {
"filters": {
"filters": {
"foo": {
"terms": {
"foo": ["bar"]
}
},
"baz": {
"terms": {
"baz": ["quux"]
}
}
}
}
}
}
}

关于elasticsearch - Nest NamedFilters 需要 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64754798/

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