简体   繁体   English

Mongo Atlas 搜索索引数字字段精确匹配搜索

[英]Mongo Atlas Search Index numeric field exact match search

We are using MongoDB Atlas Search Indexes to query and filter the documents list.我们正在使用 MongoDB Atlas Search Indexes 来查询和过滤文档列表。 consider below document.考虑以下文件。

{_id:5sfgdfgf2c46e0fb00019bdecc, user_id:4996, bom_number:"112", name:"test"} {_id:5sfgdfgf2c46e0fb00019bdecc, user_id:4996, bom_number:"112", name:"test"}

Created default Index:创建的默认索引:

{ "mappings": { "dynamic": false, "fields": { "user_id": { "type": "string" } } } } {“映射”:{“动态”:假,“字段”:{“user_id”:{“类型”:“字符串”}}}}

Query:询问:

{ text: { query: ["4996","3888"], path: 'user_id' } } {文本:{查询:[“4996”,“3888”],路径:'user_id'}}

It is not returning any documents.它不返回任何文件。 Can anyone please guide.任何人都可以请指导。 I know we actually stored user_id as numeric form and I tried indexing and querying the field as String.我知道我们实际上将 user_id 存储为数字形式,我尝试将该字段作为字符串进行索引和查询。 Please help me out and suggest correct way of querying mongo atlas numeric field with multiple values.请帮助我并建议使用多个值查询 mongo atlas 数字字段的正确方法。

$search is what you need to use to query using the index that you have created and you also need to mention the name of the index in the query. $search是您需要使用已创建的索引进行查询的内容,您还需要在查询中提及索引的名称。

The below draft might help you:以下草稿可能对您有所帮助:

$search:{
 {
  index: "index_name_created_from_atlas_search",
  text: {
    query: "<actual data you need to search>",
    path: "<field_name>"
  }
 }
}

And based on your example, if you want to have multiple conditions with the search, you can refer to official documentation here of all sorts of multiple conditions you can integrate with the $search aggregation using the compound operator.根据您的示例,如果您想在搜索中有多个条件,您可以参考官方文档here ,您可以使用compound运算符与$search聚合集成各种多个条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mongo db atlas search:在嵌入式文档上创建 atlas 搜索索引 - Mongo db atlas search: create atlas search index on embedded document Mongo Atlas 搜索索引,用于部分匹配和不区分大小写的查询 - Mongo Atlas search index for both partial matches and case-insensitive queries 有没有办法在 MongoDB(使用 Atlas Search)的搜索索引中包含 Int32 字段? - Is there a way to include a Int32 field in a search index in MongoDB (with Atlas Search)? 如何 mongodb 搜索嵌套文档并找到完全匹配的字段 - how to mongodb search nested documents and find exact match field 使用 Mongo Atlas Search 将数字作为关键字或字符串进行搜索(尽可能在 Elastic Search 中) - Searching numbers as keywords or strings with Mongo Atlas Search (as possible in Elastic Search) 确定Mongo在哪个字段上找到了$ text $ search匹配项 - Determining which field Mongo found a $text $search match on MongoDB Atlas - $search v/s $match - MongoDB Atlas - $search v/s $match MongoDB Atlas Search index on normalized/indexed model - MongoDB Atlas Search index on normalized/indexed model MongoDB Atlas 搜索自动完成索引错误评分 - MongoDB Atlas Search autocomplete index wrong scoring 对 ObjectId 字段的 Atlas 搜索不起作用 - Atlas search on an ObjectId field doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM