Reputation: 8661
I am using ES for my laravel app as an search engine.
But when it comes to mapping i am not sure whenever to use integer or long for my numbers?
I have a MySql DB that adds data live to my ES database.
I need to make my numbers searchable or sortable. Eg sort by price or search by price.
I cant find anything in the docs saying when to use integer or long.
Thanks in advance
Upvotes: 2
Views: 5112
Reputation: 5918
If you are aware of the maximum value that will be stored for your numeric fields, then, I would suggest to go for the exact type that is enough for your field. ie, do not use long
, if integer
is enough. The docs https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#_which_type_should_i_use explicitly mentions this :
As far as integer types (byte, short, integer and long) are concerned, you should pick the smallest type which is enough for your use-case. This will help indexing and searching be more efficient
Upvotes: 0
Reputation: 62368
The only difference between int and long is the size of the number that can be represented. Basically, int is a 32 bit signed integer, and long is a 64 bit signed integer. So, if the value you need to represent is larger than 231 - 1, then you need to use a long.
To ensure that you can search/sort by your field, you need to make sure that it is indexed (not_analyzed).
Elasticserach mapping documentation.
Elasticsearch core types documentation.
Java primitive types documentation.
Upvotes: 3