Closed d4ilys closed 2 weeks ago
Hi @d4ilys,
this is not an issue with the library. The correct syntax would be:
var searchResponse = await client.SearchAsync<Person>(search => search
.Index("jointest")
.Query(q => q
.Bool(descriptor => descriptor
.Filter([ // <- note the collection initializer syntax
m => m.Term(mm => mm.Field(f => f.TeacherId).Value("9669669")),
m => m.Range(f => f.DateRange(dateRangeQueryDescriptor => dateRangeQueryDescriptor
.Field(c => c.Birthday)
.Gte(DateMath.Anchored("2024-08-01T15:59:56.511"))
.Lte(DateMath.Anchored("2024-12-01T15:59:56.511"))
))
])
)
)
);
Your code did not actually add a Term
and a Range
query to Filter
. Instead, the call to Range
has overwritten the Term
query that you previously set.
I recommend using expression syntax (x => x.A()
) for lambda descriptor actions instead of statement syntax (x => { x.A() }
). With statement syntax it's very easy to do mistakes like in your code example.
For lists, there is always an overload that accepts a list/an array of descriptors.
Please let me know, if that solves your issue.
Hi @flobernd !
Thank you for your reply. The issue has been resolved, but it is indeed easy to make mistakes here😂
Elastic.Clients.Elasticsearch version: 8.15.5
Elasticsearch version: 8.9.1
.NET runtime version: 8.0
Operating system version: Windows 11
Description of the problem including expected versus actual behavior: A clear and concise description of what the bug is.
Steps to reproduce: 1.When using Bool Filter to query, the relationship between Term and Range is not 'And', which is inconsistent with the native DSL query results
Expected behavior A clear and concise description of what you expected to happen.
Please refer to the following example