How to set up atlas search index with autocomplete for field inside an array?

Hi,

I have following structure of document

{
title : “some title”,
someData: [
{ itemNo: “1”, description: “dpcxed”},
{ itemNo: “2”, description: “edfic”},
]
}

how to setup atlas search index with autocomplete, for each description in someData array?
And how to query it?

I’v read this post :

and it is stated here, that the work on this feature is in progress?
Could you provide me working example with this setup?
And also how to query it.

Thanks in advance

Hi @urosbrkic1_N_A ,

  1. If you don’t need element-wise matching, you can define someData as a document field mapping type and define child fields as the autocomplete type. Example in the Search Playground.
  2. If you need element-wise matching, you can use define someData as an embeddedDocuments field mapping type and define child fields as the autocomplete type. Example in the Search Playground.

Both examples search for documents where:

  • someData.itemNo is 2
  • someData.description matches autocomplete for dpc

The first example returns documents as long as all search criteria are met across any nested documents within someData. The second example requires that the search criteria is met by the same nested document within someData . Since there is no child document which matches both clauses, no documents match the criteria.

This tutorial about how to use Atlas Search with arrays of objects might be helpful for you! Let me know if you have any additional questions.