Sample DATA:
{
"_id": 1,
"title": "Redmi 6 Pro - Red",
"ram": "4 GB"
},
{
"_id": 2,
"title": "Redmi large One",
"ram": "1 GB"
},
{
"_id": 3,
"title": "Redmi Note 8",
"ram": "4 GB"
},
{
"_id": 4,
"title": "Redmi diamond colour",
"ram": "2 GB"
}
I’ve created an index with dynamic
Mapping ON.
My aggregation:
[{
'$search': {
'index': 'default',
'compound': {
'must': [
{
'text': {
'query': 'redmi', // searching redmi on field "title"
'path': 'title'
}
}
],
'filter': {
'text': {
'query': '4 GB', // docs which have "4 GB" ram only
'path': 'ram'
}
}
}
}
}]
I wanted those documents which have only “4 GB” ram
Like this (Expected Output):
{
"_id": 1,
"title": "Redmi 6 Pro - Red",
"ram": "4 GB"
},
{
"_id": 3,
"title": "Redmi Note 8",
"ram": "4 GB"
}
But, I’m getting all my documents returned.
Like this:
{
"_id": 1,
"title": "Redmi 6 Pro - Red",
"ram": "4 GB"
},
{
"_id": 2,
"title": "Redmi large One",
"ram": "1 GB"
},
{
"_id": 3,
"title": "Redmi Note 8",
"ram": "4 GB"
},
{
"_id": 4,
"title": "Redmi diamond colour",
"ram": "2 GB"
}
Please Make Sure:
ram:"4GB"
ram:"4 GB"
How to fix this ?
Thanks