I'm having problem to reproduce search result in OpenSearch / ElasticSearch from DSL query to .NET C# code base.
Index was populated from .NET Core application based on this model:
public class Car
{
public string Producer { get; set; }
public string Model { get; set; }
public string Vin { get; set; }
public ColorEnum Color { get; set; }
public TransmissionType Transmission { get; set; }
public CategoryType Category { get; set; }
}
Index mapping for model above looks like this:
"mappings": {
"_doc": {
"properties": {
"transmission": {
"type": "long"
},
"color": {
"type": "long"
},
"producer": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"model": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"vin": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"category": {
"type": "long"
}
}
}
Below is working as expected DSL query
{
"query": {
"bool": {
"must": [
{ "term": { "color": 0 }},
{ "term": { "transmission": 0 }},
{ "term": { "producer": "volvo" } }
]}}
}
The C# query that uses OpenSearch or ElasticSearch .NET Client and should produce that same outcome as DSL query is not respecting all required terms.
var documents = await _openSearchClient.SearchAsync<Car>(s => s
.Index(_indexName)
.Query(q => q
.Bool(b => b
.Must(m => m.Term("category", 0))
.Must(m => m.Term("transmission", 0))
.Must(m => m.Term("producer", producer)))));
return documents?.Documents;
The outcome of C# API call contain also documents that have category values set to 1 and transmission set to 1. It looks like only last term with producer name is respected.
Do i made mistake in c# query or there is something how to queries are executed ?
Thanks for all the help.