简体   繁体   中英

Mongo Atlas Search Index numeric field exact match search

We are using MongoDB Atlas Search Indexes to query and filter the documents list. consider below document.

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

Created default Index:

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

Query:

{ text: { query: ["4996","3888"], path: '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. Please help me out and suggest correct way of querying mongo atlas numeric field with multiple values.

$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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM