Having some issues with atlas $search and compound querying of faceted/arrays.
Take the following dataset:
[
{
"_id": "one",
"category": "bear",
"tags": ["202"],
"text": "This is some text"
},
{
"_id": "two",
"category": "bear",
"tags": ["202-L"],
"text": "This is some text"
},
{
"_id": "three",
"category": "bear",
"tags": ["204-L"],
"text": "This is some text"
}
{
"_id": "four",
"category": "tiger",
"tags": ["202"],
"text": "This is some text"
}
]
I’m using the above data with the following $search aggregate:
{
index: "text",
facet: {
operator: {
compound: {
filter: [
{
text: {
path: [
"text",
],
query: "some",
},
},
{
text: {
path: "category",
query: "bear",
},
},
{
text: {
path: "tags",
query: "202"
},
},
],
},
},
facets: {
tags: {
type: "string",
path: "tags",
},
},
},
}
My problem is specifically around the tags field. I only want documents to be returned that explicitly match “202” but that isn’t what is happening.
{
text: {
path: "tags",
query: "202" // or ["202"]
}
}
The above returns document “one” and “two” but I would only expect document “one” to be returned. It seems that it is matching the “202” in the tag values and not acknowledging that “202” != “202-L”
If I change the filter to the following:
{
text: {
path: "tags",
query: "202-L"
}
}
It returns “one”, “two”, and “three” when I would only expect it to return document “two”. It appears to be matching the “202” and the “-L” across all documents.
I’ve read through the documentation and just can’t figure out what I am missing. How can I go about only matching explicit strings in an array and not partial values?