'Why does mapping numeric data to a keyword improve retrieval times in ElasticSearch

I'm coming from a long-term SQL background -- NoSQL (and ElasticSearch) is very new to me.

An engineer on my team is constructing a new index for document storage, and they have mapped all short/int/long values to strings for use in term queries.

This surprised me, as a SQL index with an SmallInt/Int/BigInt key will perform much better than that same set of values turned into a VarChar(X) and indexed accordingly.

I was pointed to this article: https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html

Which has this comment:

Consider mapping a numeric identifier as a keyword if:

  • You don’t plan to search for the identifier data using range queries.
  • Fast retrieval is important. term query searches on keyword fields are often faster than term searches on numeric fields.

I'm happy take this at face value, but I don't understand why this is.

Assuming an exact match type query (e.g. ID = 100), can anyone speak to the mechanics of ElasticSearch (or NoSQL in general), that would explain why a query against a stringified numeric value is faster than a query against numeric values directly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source