[英]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.