Elasticsearch 映射整数或长
Elasticsearch mapping integer or long
我正在为我的 laravel 应用程序使用 ES 作为搜索引擎。
但是当涉及到映射时,我不确定何时对我的数字使用整数或长整数?
我有一个 MySql 数据库,可以将数据实时添加到我的 ES 数据库中。
我需要让我的号码可以搜索或排序。例如按价格排序或按价格搜索。
我在文档中找不到任何说明何时使用整数或长整数的内容。
提前致谢
int 和 long 之间的唯一区别是可以表示的数字的大小。基本上,int 是一个 32 位有符号整数,long 是一个 64 位有符号整数。所以,如果你需要表示的值大于231 - 1,那么你需要使用long.
为确保您可以 search/sort 通过您的字段,您需要确保它已编入索引 (not_analyzed)。
Elasticserach mapping 文档。
Elasticsearch core types 文档。
Java primitive types 文档。
如果您知道将为您的数字字段存储的最大值,那么,我建议您选择适合您的字段的确切类型。即,如果 integer
足够,则不要使用 long
。文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#_which_type_should_i_use 明确提到了这一点:
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
我正在为我的 laravel 应用程序使用 ES 作为搜索引擎。
但是当涉及到映射时,我不确定何时对我的数字使用整数或长整数?
我有一个 MySql 数据库,可以将数据实时添加到我的 ES 数据库中。
我需要让我的号码可以搜索或排序。例如按价格排序或按价格搜索。
我在文档中找不到任何说明何时使用整数或长整数的内容。
提前致谢
int 和 long 之间的唯一区别是可以表示的数字的大小。基本上,int 是一个 32 位有符号整数,long 是一个 64 位有符号整数。所以,如果你需要表示的值大于231 - 1,那么你需要使用long.
为确保您可以 search/sort 通过您的字段,您需要确保它已编入索引 (not_analyzed)。
Elasticserach mapping 文档。
Elasticsearch core types 文档。
Java primitive types 文档。
如果您知道将为您的数字字段存储的最大值,那么,我建议您选择适合您的字段的确切类型。即,如果 integer
足够,则不要使用 long
。文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#_which_type_should_i_use 明确提到了这一点:
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