Is it better to store integers instead of full text? Is it better to store integers instead of full text? elasticsearch elasticsearch

Is it better to store integers instead of full text?


For filters it's not likely to make a difference. Something to keep in mind, however, is that during an aggregation, doc-valued string fields (eg non analyzed ones) are going to be loaded into an on-heap memory map called global ordinals. Depending on the number of possible values (which for gender will presumably be very small) that can exert a great deal of pressure on the JVM.

You might try mapping this as a boolean field, potentially. You'd save a bit of space if you did that, or if you mapped it as a integer. But from a querying perspective, it should make any difference.

As far as MySQL vs ES, that's a trickier and much more nuanced question. It depends on (among other things) what you are trying to do, how much data you're working with, and whether or not you require transactional guarantees and/or MVCC. Both MySQL and ES will perform quite well with a filter like this (assuming you put a secondary index on gender in MySQL... which in effect would be a B-Tree based version of the relationship mapped by Lucene). Based on the info you've provided, there isn't really a good reason to prefer one tool over another. You'd either need to provide more context or (perhaps even better) give it a shot in both and see which one you're happier with.

Best of luck.