Hi all,
i need your help on implementing an atlas search index, i’m struggling to make it work as i expect.
I have actually this type of data :
{
"_id": {
"$oid": "5c9a407f1868e7ffb638a4c5"
},
"providers": [
{
"city": "NEW YORK",
"code": "code1",
"name": "NAME1",
"type": "type1",
"validFrom": {
"$date": "2023-07-01T00:00:00.000Z"
}
},
{
"city": "NEW YORK",
"code": "code2",
"name": "NAME1",
"type": "type2",
"validFrom": {
"$date": "2023-11-01T00:00:00.000Z"
}
}
],
"type" : "ST",
"destinationCode": "destCode",
"originCode": "orgCode",
"creationDate": {
"$date": "2024-01-08T12:09:48.243Z"
}
}
and i’m trying to reproduce this $find clauses using Atlas Search :
{
providers: {
$elemMatch : {
code : 'code1' ,
type: 'type1',
validFrom: {$lte: ISODate('2023-09-11T08:56:22.012+00:00')}
}
}, type : 'ST'
}
So, after reading some documentation and community posts, I started to work on embeddedDocument concepts in order to replace this $elemMatch, and i defined the below Atlas Search index :
{
"mappings": {
"dynamic": false,
"fields": {
"providers": {
"type": "embeddedDocuments",
"fields": {
"code": {
"type": "string"
},
"type": {
"type": "string"
},
"validFrom": {
"type": "date"
}
}
},
"type": {
"type": "token"
}
}
}
}
And the atlas search query :
{
index: "default",
"embeddedDocument": {
"path": "providers",
"operator": {
"compound" :{
"must" : [{
"text": {
"path": "providers.code",
"query": "code1"
},
"text":{
"path" : "providers.type",
"query":"type1"
}
}] ,
"filter" : [{
"range" : {
"path": "providers.validFrom",
"lt": ISODate('2023-09-11T08:56:22.012+00:00')
}
}]
}
}
}
}
But the results are not the expected one, in the sense it seems not taking the embeddedDocument in account, and returning data which have either the providers.code matching or the providers.type or providers.validFrom, but not only those having three criteria matching.
I don’t understand what i’m doing wrong, and i tried actually a lot of other combinations without sucess.
Could you please help telling me what is not good in my query ?