I'm currently working on an Elasticsearch query in Kibana, and I need help converting it to .NET Elastic client code. Below is my Kibana query and the partial .NET code I've written so far. I'm using Elasticsearch version 8.10.
I'm having trouble converting the full query, especially the range queries. Could someone help me with the complete translation of the above Kibana query to .NET Elastic client code?
Kibana Query:
POST searchIndex/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"destinationName.keyword": ["Hurghada", "Majorca"]
}
},
{
"terms": {
"deptcode.keyword": ["LGW", "LCY", "LHR", "STN", "LTN", "SEN"]
}
},
{
"range": {
"price": {
"lte": 2000
}
}
},
{
"range": {
"deptDate": {
"gte": "2025-03-30T23:15:00",
"lte": "2025-05-07T17:50:00",
"format": "strict_date_optional_time"
}
}
},
{
"terms": {
"rating.keyword": ["2", "4"]
}
},
{
"terms": {
"bid": [8, 3]
}
}
]
}
},
"sort": [
{
"price": {
"order": "asc"
}
}
]
}
Partial .NET Elastic Client Code
var result = await _elasticClient.SearchAsync<SearchHotelBespoke>(s => s
.Index("searchIndex")
.Query(q => q.Bool(b => b.Must(
mu => mu.Terms(t => t
.Field(f => f.DestinationName.Suffix("keyword"))
.Terms(new TermsQueryField(dnNames.Select(d => FieldValue.String(d)).ToArray()))),
mu => mu.Terms(t => t
.Field(f => f.DepartureCode.Suffix("keyword"))
.Terms(new TermsQueryField(deptc.Select(d => FieldValue.String(d)).ToArray())))
))));