MongoDB文本索引错误:不支持语言覆盖 [英] MongoDB Text Index Error: language override not supported

查看:260
本文介绍了MongoDB文本索引错误:不支持语言覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2.6.1版.我正在尝试创建文本索引,但出现错误:

I am using version 2.6.1. I am trying to create a text index and I'm getting error:

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

要搜索的文档具有一个"language"字段,其值为"en-US",但在文本搜索中不用于覆盖该语言.我试图创建文本索引来指定一个不存在的字段("lang");但是,我得到了同样的错误. 我能够在版本2.6.0上很好地创建索引.有没有办法创建文本索引并忽略language_override字段?

The documents being searched have a "language" field that has a value of "en-US", but it is not used to override the language in a text search. I tried to create the text index to specify a field that doesn't exist ("lang"); however, I get the same error. I was able to create the index just fine on version 2.6.0. Is there a way to create the text index and ignore the language_override field?

这是我在2.6.0上使用的有效命令(不适用于2.6.1):

Here is the working command I used on 2.6.0 (doesn't work on 2.6.1):

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

这是我在2.6.1上尝试的命令,用于指定另一个不存在的language_override字段:

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" })

提前谢谢!

推荐答案

解决方案:

default_languagelanguage_override设置为相同的文字值(在您的情况下为"en").

Solution:

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

我在Mongo 2.6.1上也遇到了同样的问题.

I hit the same problem, also on Mongo 2.6.1.

在我的情况下,我创建了一个language_override索引,该索引指向一个语言字段,在该语言字段中已经存在不支持值的文档(例如'ar'-阿拉伯语).

In my case I created the index with a language_override pointing to a language field where there were already documents with unsupported values (e.g. 'ar' - Arabic).

这是我创建索引的方式:

Here's how I was creating the index:

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

我希望当language_override值不受支持时,它会回落到default_language,但显然不支持.这是Mongo所说的:

I was hoping it would fall back to the default_language when the language_override value is unsupported, but apparently not. Here's what Mongo says:

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

好的,很好,因此没有创建索引,但是我应该能够在没有language_override的情况下创建索引,对吗?错误-mongo给我同样的错误,即使我不再指定language_override .

OK, fine, so the index wasn't created but I should be able to create it without the language_override, right? Wrong - mongo gives me the same error even though I no longer have the language_override specified.

创建索引的失败尝试似乎遗留了索引的某个损坏的版本,该版本未显示在任何地方,因此我无法删除它(它未出现在db.users.getIndexes()中,并且按名称删除它不会不起作用).

The failed attempt at creating the index seems to have left behind some broken version of the index that does not show up anywhere so I can't drop it (it doesn't appear in db.users.getIndexes() and dropping it by name doesn't work).

最后,我设法通过将language_override设置为文字值"en"来修复索引,如下所示:

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

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

... Mongo回复:

... to which Mongo replies:

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

Hurrah.

这篇关于MongoDB文本索引错误:不支持语言覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆