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 |
---|---|---|---|
Aggregations: Use $cond without an else clause | 2 | 852 | May 2024 |
New Atlas Search Feature: Search Query Templates | 0 | 540 | May 2024 |
How to use Atlas Search with lookup collections | 0 | 39 | Oct 2024 |
Run mongorestore in mongodb/mongodb-atlas-local image | 0 | 36 | Dec 2024 |
Mongo Atlas Vector Serch | 2 | 36 | Feb 18 |