【发布时间】:2016-07-24 20:12:18
【问题描述】:
我有这个 elasticsearch 查询,它以原始格式完美运行,但我无法将其转换为 C# NEST 子句。
这是原始查询:
{
"query":{
"constant_score":{
"filter":{
"bool":{
"must":{
"term":{
"ingredients":"baking"
}
},
"must":{
"term":{
"ingredients":"soda"
}
}
}
}
}
}
}
这就是我认为在 C# NEST 中可以使用的:
public List<Recipe> FindByMultipleValues(string field, string[] values) {
List<string> vals = values.ToList();
return client.Search<Recipe>(s => s
.Query(q => q
.Bool(fq => fq
.Filter(f => f
.Term(rec => rec.Ingredients, vals)
)
)
)
).Documents.ToList();
}
用户可以发送一个 x 值的数组,这意味着对于每个值必须有一个:
"must":{
"term":{
"ingredients":"soda"
}
}
【问题讨论】:
-
must查询的bool子句是一个数组;我怀疑第二个must子句属性最终会覆盖第一个。您使用的是哪个版本的 NEST? -
我使用的是最新版本。 2.3.x 我认为是。
标签: c# elasticsearch nest