【问题标题】:Mongodb Atlas Search with directive insensitive指令不敏感的Mongodb Atlas Search
【发布时间】:2021-01-05 19:13:24
【问题描述】:

我正在使用 MongoDB Atlas Search 在 Collection 中执行搜索,为此我创建了 Atlas Search Index:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "caption": {
        "type": "string"
      }
    }
  }
}

这是我的聚合:

[
   {
      "$search":{
         "text":{
            "path":"caption",
            "query":"Ingocnitáá",
            "fuzzy":{
               
            }
         },
         "highlight":{
            "path":"caption"
         }
      }
   }
]

我的收藏中有以下文档:

{caption:"Ct tyu test Ingocnitáá"}

问题:当我搜索Ingocnitaaagreement 返回 0 结果。

我的搜索索引有什么问题吗?我想要一个带有突出显示的指令不敏感搜索。

【问题讨论】:

    标签: mongodb mongodb-atlas mongodb-atlas-search


    【解决方案1】:

    缺少两件事:

    1. 包含索引名称(建议不要使用默认索引,新建索引)
    2. 总是通过fuzzy:{}

    这是一个有效的查询:

    [
      {
           "$search":{
              "index": 'messageText',
              "text":{
                 "path":"caption",
                 "query":"Ingocnitaa",
                 "fuzzy":{
    
                 }
              },
              "highlight":{
                 "path":"caption"
              }
           }
        }
    ]
    

    messageText 是搜索索引名称。


    搜索索引格式:

    {
      "mappings": {
        "dynamic": false,
        "fields": {
          "caption": {
            "type": "string"
          }
        }
      }
    }
    

    参考:CLick here

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 2021-12-26
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多