hey will the sort works for the string fields inside the $search stage for me only date fields are working and not the string fields
Hey Mahendra, welcome!
Might be helpful for you to share the search index definition so we can provide a bit more focused response… You can view or edit it in the Atlas UI → Search tab → Indexes → Edit JSON
You’ll probably want to append a $sort stage AFTER your $search stage… something like:
$search: {
index: "default",
text: {
query: "example",
path: "yourFieldName"
}
}
},
{
$sort: {
"yourFieldName": 1
}
}
For sorting with $search, numeric and date field types are automatically mapped and available. String fields currently require explicit token
type mapping so they are indexed properly for sort-ability. See https://www.mongodb.com/docs/atlas/atlas-search/sort/ for more details.
While your example, Michael, will work - there’s an impedence mismatch between $search and successive stages, and stages like $group and $sort that consume all documents could cause a big performance hit. It’s best when using $search and needing to sort to do so with the sort options within the $search
stage.
thank you this worked
I’m currently working with a MongoDB collection where we have a field named customAttributes
, which contains dynamic subfields that vary from customer to customer.
We are trying to enable wildcard search on these dynamic subfields using Atlas Search. Since the keys inside customAttributes
are not consistent across documents, we attempted to use a dynamic mapping with wildcard support.
Could you please confirm the correct syntax for the search index definition that would:
- Enable wildcard search on all subfields inside
customAttributes
- Work with dynamic keys
- Use the appropriate
keyword
analyzer to support wildcard queries
If possible, could you share a sample index definition that would meet the above requirements?
my main need is to make it work like contains operator that can search with special character’s tooo
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
How to return ALL facets if there are more than 1000 | 1 | 487 | Jun 2024 |
Group by aggregation not using index COUNT_SCAN | 0 | 387 | Jul 2024 |
How to index in Atlas Search a string field that store in fact a number | 4 | 83 | Oct 2024 |
Unable to access MongoDB Atlas after Google account deactivation | 0 | 24 | Oct 2024 |
How to search embeddedDocuments fields and non-embeddedDocuments fields using Atlas Search | 3 | 55 | Oct 2024 |