Mongo Db search by indexed field

前端 未结 2 520
别跟我提以往
别跟我提以往 2021-01-14 15:38

I add field \'search_string\' to my document and index it. db.my_collection.createIndex({search_string: \"text\"}) Search_string contains this: \'a ar are aren

相关标签:
2条回答
  • 2021-01-14 16:22

    By default, MongoDB uses English for text index and the stop words are not indexed.

    If you specify a language value of "none", then the text search uses simple tokenization with no list of stop words and no stemming.

    So you should create your index like this :

    db.my_collection.createIndex( { search_string : "text" }, { default_language: "none" } )

    MongoDB documentation here.

    0 讨论(0)
  • 2021-01-14 16:39

    From the MongoDB manual

    Match Operation

    Stop Words

    The $text operator ignores language-specific stop words, such as the and and in English.

    Both "a" and "are" are in the list of default English language stopwords so will be ignored. A quick google search for English language stopwords will find plenty of pages with the full list.

    0 讨论(0)
提交回复
热议问题