0

I am having some trouble with the autocomplete atlas search data type when trying to define an index for an array of subdocuments in my document.

My data structure for the documents in my collection looks like this:

{
   "data": {
     "equipment": {
       "entries": [
         {
           "name": "abcdefg"
         }
         {
           "name": "hijklmno"
         }
       ]
     }
   }
}

When I define a string index for searching the entries array, it works as intended and I get logical results. Here is my index definition using the lucene.keyword analyzer:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data": {
        "fields": {
          "equipment": {
            "fields": {
              "entries": {
                "fields": {
                  "name": {
                    "analyzer": "lucene.keyword",
                    "searchAnalyzer": "lucene.keyword",
                    "type": "string"
                  }
                },
                "type": "document"
              }
            },
            "type": "document"
          }
        },
        "type": "document"
      }
    }
  }
}

However, when I try the same thing with the autocomplete type, I get an empty result, but no error. Here is how I defined the autocomplete:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data": {
        "fields": {
          "equipment": {
            "fields": {
              "entries": {
                "fields": {
                  "name": {
                    "tokenization": "nGram",
                    "type": "autocomplete"
                  }
                },
                "type": "document"
              }
            },
            "type": "document"
          }
        },
        "type": "document"
      }
    }
  }
}

The documentation for Atlas Search states the following: The autocomplete type can't be used to index fields whose value is an array of strings. So either this sentence has to be changed to say all kinds of arrays or I am doing something wrong here. Can someone clarify if this is even possible? Thanks in Advance

jakobn
  • 16
  • 1
  • 7
  • Did you find an answer? – Stone Mar 28 '21 at 01:30
  • @Stone not an answer for my original question, be we managed to build a workaround using normal string indices instead of ngram and queries utilising the wildcard feature. – jakobn Mar 29 '21 at 12:08
  • @jakobn I'm running into the same problem, glad to see I'm not alone after struggling with it for a while. Can you share a little more about the approach you took for the workaround? Thanks! – tajji Apr 05 '21 at 03:46

1 Answers1

0

Your syntax is completely wrong. its would be like:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "data.equipment.entries.name": [
        {
          "type": "autocomplete",
          "tokenization": "nGram",
          "minGrams": 3,
          "maxGrams": 7,
        }
      ]
    }
  }
}

But I am not sure that,if it support on array of document, But let me know if your problem is solved.

Stone
  • 241
  • 1
  • 4
  • 18
  • I think autocomplete feature is only for mongodb atlas .Are you using atlas ? – Stone Mar 30 '21 at 00:21
  • i have same issue. For creating text index type:'string' works fine... but for autocomplete on array of strings how do i mention the type? shall i mention type:'string' only? or type:'autocomplete' ? –  Apr 07 '21 at 08:09
  • @Stone yes i am using atlas. the problem here is not my syntax, as the visual editor produces my exact json output, therefore I should be able to assume it is valid. My guess (also @John) is, that the autocomplete type is just not applicable to this use case – jakobn Apr 07 '21 at 13:08
  • oh ok.. so is there other way i can use search on array of strings? –  Apr 07 '21 at 15:39