Create a mongodb text index with no default language

青春壹個敷衍的年華 提交于 2021-02-08 06:40:00

问题


I'M trying to create a text index without a default language. The official docs specify If you specify a language value of "none", then the text search uses simple tokenization with no list of stop words and no stemming. Hence I tried:

createIndex({aliases : "text"}, {name : "aliases_txt"}, {default_language: "none"})

However the created index ignores my option and has "english" as default language:

{
"v": 1,
"key": {
  "_fts": "text",
  "_ftsx": 1
},
"name": "aliases_txt",
"ns": "ner-dict.ents",
"weights": {
  "aliases": 1
},
"default_language": "english",
"language_override": "language",
"textIndexVersion": 2
}

version: mongod-3.0.3


回答1:


In fact, in your solution, the name value is ignored. If you want to specify both index name and default_language, you need to use:

db.textTest.createIndex({aliases : "text"}, {name : "aliases_txt", default_language: "none"});

with both name and default_language in the same 'options' document parameter.




回答2:


I just had to change the order: db.ents.createIndex({aliases : "text"}, {default_language: "none"}, { name: "aliases_txt"})



来源:https://stackoverflow.com/questions/33879398/create-a-mongodb-text-index-with-no-default-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!