我正在研究Elasticsearch NEST Client for .NET。 我必须在ES中实现CASE语句quivaleitn查询。
CASE
WHEN [CompanyId] <> 1 AND VisibilityId=1 AND [Publish] = 1 AND StatusId = 1 THEN 1
WHEN [OrganizationId] = 1 THEN 1
ELSE 0
END = 1
显然我不知道如何做到这一点。在过去的两天里,我正在进行研究,但一无所获。
它可以和条款过滤器一起使用,就像我在之前的行中所做的那样:
new FilterDescriptor<MyClass>()
.Term("OrganizationId", 1)
答案 0 :(得分:1)
我通过将Bool Query
和Or Filter
合并为:
new FilterDescriptor<ListingViewDTO>()
.Or(fo => fo.Bool(b => b.Must(c => c.And(
fs => !fs.Term("OrganizationId", compositeFilter.OrganizationId),
fs => fs.Query(q => q.Fuzzy(n => n.OnField("ListingAttributeDTO.AttributeName").Value("ListingPublish"))),
fs => fs.Query(q => q.Fuzzy(n => n.OnField("ListingAttributeDTO.Value").Value("1"))),
fs => fs.Term("VisibilityId", (int)Visibility.AnyOne),
fs => fs.Term("StatusId", 2)))),
fo => fo.Term("OrganizationId", compositeFilter.OrganizationId));