我想用和/或子查询组合过滤结果。我该怎么办?
is_active: true
category_id: [1,2,3,4]
brand: "addidas"
SubscriberID=4,
gender: "male"`enter code here`
InvoiceDetails: [
{
"ID" : 1,
"InvoiceID" : 1,
"Qty" : "1",
"Rate" : 1
},
{
"ID" : 2,
"InvoiceID" : 1,
"Qty" : "1",
"Rate" : 1
}]
SQL:
SELECT .... WHERE
SubscriberID= 4 AND InvoiceDetails.InvoiceID =2
OR (brand='addidas' AND gender='male')
如何使用C#NEST HighLevel编写以上SQL?
我找到了嵌套查询,但没有找到任何可行的示例?
我在下面的查询中尝试过
.Query(q =>
q.Bool
(
b => b.Filter
(
f => (
f.Term(t => t.Field(fd => fd.SubscriberID).Value(8)) &&
f.Term(t => t.Field(fd => fd.CompanyID).Value(2019))
&& f.Nested(
n => n.Path(p => p.InvoiceDetails)
.Query
(
c => c.Term
(
t => t.Field(fd => fd.InvoiceDetails.FirstOrDefault().InvoiceID).Value("121123")
)
)
)
//f.Term(t => t.Field("InvoiceDetails.InvoiceID").Value("1015312"))
)
)
)
)
装有嵌套查询,如果我在下面的查询中编写,则可以。我不认为我在嵌套查询中错了什么。
f.Term(t => t.Field("InvoiceDetails.InvoiceID").Value("1015312"))
其他信息:以下是我的POCO类,在该类的上方,我具有嵌套属性。
public class Invoice
{
public long ID { get; set; }
[Nested]
[PropertyName("InvoiceDetails")]
public List<InvoiceDetails> InvoiceDetails { get; set; }
}
public class InvoiceDetails
{
public long ID { get; set; }
[Number(NumberType.Long, Name = "InvoiceID")]
public long InvoiceID { get; set; }
}