How to perform atlas $search on a nested field but only at a specific index. For example, I have an array of objects called “chunks”. I have created the index on the chunks and set the mapping as “dynamic”: true. Below is a sample of two documents
Document 1:
{ chunks: [ { text: "lorem" }, { text: "ipsum" }, { text: "lorem" } ] }
Document 2:
{ chunks: [ { text: "lorem" }, { text: "ipsum" }, { text: "doler" } ] }
Now, If I perform this query
{
$search: {
text: {
query: "lorem",
path: "chunks.text",
}
}
}
It will return both the documents because the text is present in both the documents. Now what I want the query to perform is like this, to search for a text at a defined path at a specific index in an array rather than searching through all indices
{
$search: {
text: {
query: "lorem",
path: "chunks.2.text",
}
}
}
Is this possible ? If not directly using atlas search, is there a work around on how I can achieve it ?