我正在尝试将以下DSL查询转换为.net NEST查询,我使用的是版本5.2的elasticsearch。
{
"size": 10,
"from": 0,
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "finished",
"fields": [
"title",
"content"
]
}
}
],
"filter": {
"bool": {
"must": [
{
"term": {
"applianceTypeId": "2a682cf7-5fe3-470f-81b2-a74e00ec7c9d"
}
},
{
"term": {
"applianceCategoryId": "bde32268-b62f-45cc-8d7d-a74a00d61476"
}
}
]
}
}
}
}
}
到目前为止,我已经得到了以下内容,但我在处理多个术语时遇到了问题。任何人都可以建议我缺少什么吗?
var result = client.Search<AdviceSearchDocument>(x => x
.From(page -1)
.Size(10)
.Query(q => q
.Bool(b => b
.Must(m => m
.MultiMatch(mm => mm
.Query(query)
.Fields(f => f
.Fields(f1 => f1.Title, f1 => f1.Content))))
.Filter(f => f
.Bool(b1 => b1
.Must(m1 => m1
.Term(t =>t
.Field(fl =>fl.ApplianceTypeId)
.Value(applicanceTypeId)
)
))))));
答案 0 :(得分:0)
如果问题是如何合并applianceTypeId
和applianceCategoryId
个查询,这就是解决方案
var result = client.Search<AdviceSearchDocument>(x => x
.From(0)
.Size(10)
.Query(q => q
.Bool(b => b
.Must(m => m
.MultiMatch(mm => mm
.Query(query)
.Fields(f => f
.Fields(f1 => f1.Title, f1 => f1.Content)
)
)
).Filter(f => f
.Term(t => t
.Field(fl => fl.ApplianceTypeId)
.Value(applicanceTypeId)
) & f.Term(t => t
.Field(fl => fl.ApplianceCategoryId)
.Value(applianceCategoryId)
)
)
)
)
);