Atlas search to provide the ability to query number (long/double) fields
When querying mongo using atlas search, today it requires that the query parameter be a string. Ideally, I would like to be able to also search using numbers. Our stakeholders want the ability to type into a dropdown select field , type a number, and have it pull back a list of data.
Today, we are using atlas search to query against a multiple set of fields, and pull back the most relevant results. It would be nice to include number fields as part of our index in order to allow those same stakeholder the ability to query by the known number identifiers for that dataset with fuzzy / autocomplete.
Admin mistake! Long Numbers are also still unavailable. Reopening this and I am sorry for the confusion.
-
Paul commented
This would be great. Right now I have a trigger to convert a field into a string conversion of that field, but it stinks to have to maintain this parity between the real number and the search meta data for it. { "field": (int) } and then { "_field": (string) }. Then in the mapping: { ... "field": {"type": "number"}, {"_field": [{"type": "string"}, {"type":"autocomplete"}]} }.
It'd be great to just be able to change the mapping to: { ... "field": [ {"type":"number"}, {"type":"string"}, {"type": "autocomplete"} ] } -
Chad commented
Hey Marcus, thanks for the quick response on this.
I had ran into the number data type while reading through the documentation as well. Unfortunately, we do specifically want the ability to query using the fuzziness , and the ‘auto-complete’ / type-ahead feature that autocomplete provides. And I don’t -believe- (I could be wrong here), that querying numbers allows for those same features.
Regarding the idea regarding creating an additional field in mongo for storing the 'string'-ified version of the number, this has come up as an option internally as well, and it may be what we do in the short term, but obviously this is not ideal, since we will now need to maintain an additional field whenever we are doing updates/inserts, etc.
Appreciate your responses, and look forward to working with you some more in the future!
-
AdminMarcus Eagan (Admin, MongoDB) commented
Today, you can create a field of type number. We actually support large integers (int64) and doubles (indexDoubles boolean).
You can learn about it here: https://docs.atlas.mongodb.com/reference/atlas-search/index-definitions/#number
Fuzzy and autocomplete are text operator options for the string type, so you would need to convert the type / cast it to a string in a copied field. You can do all of these operations in Atlas as well, if need be.