MongoDB text index error: language redefinition not supported

I am using version 2.6.1. I try to create a text index and I get an error:

{ "connectionId" : 4932, "err" : "language override unsupported: en-US", "code" : 17262, "n" : 0, "ok" : 1 } 

When searching for documents, there is a "language" field, which has the value "en-US", but it is not used to override the language in a text search. I tried to create a text index to indicate a field that does not exist ("lang"); however, I get the same error. I was able to create an index just fine on version 2.6.0. Is there a way to create a text index and ignore the language_override field?

Here is the working command that I used on 2.6.0 (does not work in version 2.6.1):

 db.collection.ensureIndex({ title: "text" }, { name: "TextIndex" }) 

Here is the command I tried on 2.6.1 to specify another language_override field that does not exist:

 db.collection.ensureIndex({ title: "text" }, { name: "TextIndex" }, { language_override: "lang" }) 

Thanks in advance!

+6
source share
2 answers

Decision:

Set default_language and language_override to the same literal value (in your case, "ru").

How did I get here...

I ran into the same problem, also on Mongo 2.6.1.

In my case, I created an index with language_override , pointing to a language field where there were already documents with unsupported values ​​(for example, "ar" is Arabic).

This is how I created the index:

 db.users.ensureIndex({ "displayName": "text", "about": "text", "email": "text" }, { "name": "users_full_text", "default_language": "en", "language_override": "language" }); 

I was hoping it would return to default_language when the language_override value is not supported, but apparently not. Here is what Mongo says:

 { "createdCollectionAutomatically" : false, "numIndexesBefore" : 3, "ok" : 0, "errmsg" : "language override unsupported: ar", "code" : 17262 } 

OK, great, so the index was not created, but I would have to create it without language_image, right? Wrong - mongo gives me the same error even if I no longer have the specified language_override.

The failed attempt to create the index seems to have left behind some broken version of the index that does not appear anywhere, so I cannot drop it (it does not appear in db.users.getIndexes() and omits it by the name doesn work).

In the end, I managed to fix the index by setting language_override to the literal value 'en', for example:

 db.users.ensureIndex({ "displayName": "text", "about": "text", "email": "text" }, { "name": "users_full_text", "default_language": "en", "language_override": "en" }); 

... to which Mongo replies:

 { "createdCollectionAutomatically" : false, "numIndexesBefore" : 3, "numIndexesAfter" : 4, "ok" : 1 } 

Hurray.

+11
source

The value "en-US" is illegal as a language for indexing text according to the doc page http://docs.mongodb.org/manual/reference/text-search-languages/#text-search-languages

MongoDB accepts only two-letter code or the full name of the language.

Hope this helps :)

+3
source

Source: https://habr.com/ru/post/969720/


All Articles