Create Text Index with French Location not working

Hello,
I am using atlas and I try to create a text index with french collation but I get this error. It explains that is not supported.
Is there a way to fix it ? Because the Documentation of MongoDB explains that it is possible.
Thank’s at advance,
Farouk.

db.coll.createIndex(
...   {
...     "name": "text", 
        "description" :"text"
...   },
...   {
...     "default_language": "french"
...   }
... )
{
        "operationTime" : Timestamp(1633268024, 2),
        "ok" : 0,
        "errmsg" : "Error in specification { key: { name: \"text\" }, name: \"name_text\", default_language: \"french\", v: 2, collation: { locale: \"fr\", caseLevel: false, caseFirst: \"off\", strength: 1, numericOrdering: false, alternate: \"non-ignorable\", maxVariable: \"punct\", normalization: false, backwards: false, version: \"57.1\" } } :: caused by :: Index type 'text' does not support collation: { locale: \"fr\", caseLevel: false, caseFirst: \"off\", strength: 1, numericOrdering: false, alternate: \"non-ignorable\", maxVariable: \"punct\", normalization: false, backwards: false, version: \"57.1\" }",
        "code" : 67,
        "codeName" : "CannotCreateIndex",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1633268024, 2),
                "signature" : {
                        "hash" : BinData(0,"zpyJkmFSAFYttt42glhovt4IBZM="),
                        "keyId" : NumberLong("6978119209322545153")
                }
        }
}

Hi @Farouk_BERROUBA,

Welcome back to the forums!

In your testing, is there a non-default collation that has been applied to the coll collection itself? You can confirm this by running the command db.getCollectionInfos({name:"quotes"}).

If so, then you should be able to successfully create your index by explicitly overriding the collection’s collation in the createIndex command. By default, indexes will be created with the same collation that the index has, which could explain the error that you are receiving. A command similar to the following may run successfully in your situation:

db.coll.createIndex(
   {
     "name": "text", 
     "description" :"text"
   },
   {
     "default_language": "french",
      collation: { locale:"simple" }
   }
 )

That said, the information above applies to our older text indexes. You may wish to consider exploring the text searching capabilities provided by Atlas Search instead. Atlas Search provides a number of performance and functionality benefits, and indeed does have language-specific analyzers as well.

Best,
Chris

1 Like

Hi @Christopher_Harris ,
Thank’s a lot for your help !
The “local : simple” option was missing to the creation command. It’s working now as I need.
I will take a look to Atlas Search, I saw that it uses Apche Lucene. Is it different from the older text indexes ?
Best,
Farouk.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.