I'm struggling to generate a .Net search which will combine a must field of one value and a should search of one of two values from a different field - e.g. results must contain value1 from field1 and either value2 or value3 from field2.
I have successfully created that search in Elastic Search. See below:-
GET stagingstock/_search
{
"size" : 1000,
"query": {
"bool": {
"must": [
{
"match": {
"field1": {
"query": "value1",
"operator": "and",
"fuzziness": "auto"
}
}
},
{"bool": {
"should": [
{
"match": {
"field2": {
"query": "value2",
"operator": "or",
"fuzziness": "auto"
}
}
},
{
"match": {
"field2": {
"query": "value3",
"operator": "or",
"fuzziness": "auto"
}
}
}
]
}}
]
}
},
"sort": [
{
"updatedDate": {
"order": "desc"
}
}
]
}
But when I try to parse that query into .Net it is returning either value1, value2 or value3. Code below:
resp2 = await client.SearchAsync<ElasticStock>(s => s
.Index(index)
.Size(10000)
.Query(q => q.Bool(
b => b.Must(
mq => mq.Match(
m => m.Field(
f => f.Field1)
.Fuzziness(fuzz)
.Query(value1)
.Operator(Operator.And)
).Bool(
b2 => b2.Should(
sq => sq.Match(m2 => m2.Field(f => f.Field2).Query(value2)),
sq => sq.Match(m2 => m2.Field(f => f.Field2).Query(value3))
)
)
)
)
)
.Sort(so => so
.Field(f => f.UpdatedDate, new FieldSort { Order = SortOrder.Desc }))
);
Can someone tell me what I am doing wrong in .Net as the logic seems the same to me?
Note: I removed the Or Operators in the .Net code but that didn't make any difference to the search.