Data type coercion when document field type doesn't match index field type
When a document field type doesn't match the index field type, it seems to be indexed as "blank" and won't match anything. Many data types are readily convertible between type representations. It would be great if Atlas Search could do that for us and would open up richer functionality by allowing us to use operators/analyzers/etc. on types that don't normally support them.
My particular use case is to allow searching & sorting on numbers stored as strings. When creating indexes and sorting with "normal" queries, it is possible to sort numbers stored as strings by their numerical ordering rather than alphabetical by using { collation: { locale: "en_US", numericOrdering: true } }
on the index definition and applying query.collation(Collation.of(Locale.US).numericOrdering(true))
to the query itself. I was hoping to do this with Atlas Search Sort as well, but it isn't possible.
Examples:
string "1000.00"
= number 1000.00
boolean true
= number 1
boolean true
= string "true"
etc.
-
David commented
While this feature would be valuable for me, I've had a better idea that would solve it and all kinds of other scenarios as well:
-
David commented
Alternatively, I would also be happy if the specific case of using numeric ordering on strings were added to the new sort feature, like you can with normal queries. But generalized type coercion would be more broadly useful.