Atlas $search on a nested field in an array, but only at a specific index

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 ?

Hi @Chetan_J_Rao and welcome to the community forum!!

If I understand your question correctly, you are trying to perform the search on a specific index of the array in a document.
You can perform the same using a simple $match operation using the below query:

[
  {
    $match: {
      "chunks.2.text": "lorem",
    },
  },
]

The Atlas search index would be created on a field name and not on the index.

If there is a specific use case where you would like to use the Atlas Search feature, could you help me with more details on the same.

Please reach out in case of further questions.

Best Regards
Aasawari

Thanks, but this is not a FTS query. This is a normal match query, which does not have full text search capabilities. How can I achieve the same using $search aggregation pipeline