我願做一個ElasticSearch這樣的查詢:NEST條件篩選查詢
{
"query" :
{
"bool" :
{
"filter" : [
{
"terms" :
{
"name" : ["name1", "name2"]
}
},
{
"terms" :
{
"color" : ["orange", "red"]
}
}
]
}
}
}
我一直試圖實現它的窩是這樣的:
_elasticClient
.SearchAsync<MyDocument>(s =>
s.Index("myindex")
.Query(q => q
.Bool(bq => bq
.Filter(fq =>
{
QueryContainer query = null;
if (nameList.Any()) {
query &= fq.Terms(t => t.Field(f => f.Name).Terms(nameList));
}
if (colorList.Any()) {
query &= fq.Terms(t => t.Field(f => f.Color).Terms(colorList));
}
return query;
})
)
)
);
但是,讓我喜歡這個地方的過濾器包裹布爾必須內查詢:
{
"query" :
{
"bool" :
{
"filter" : [
{
"bool" :
{
"must" : [
{
"terms" :
{
"name" : ["name1", "name2"]
}
},
{
"terms" :
{
"color" : ["orange", "red"]
}
}
]
}
}
]
}
}
}
我應該如何更改我的NEST代碼以給我正確的查詢?是否必須將我的條款添加到另一個QueryContainer?