在ElasticSearch 5聚合中最适合使用的数据类型是什么:数字或关键字? [英] What is the most suitable datatype to use in aggregations with ElasticSearch 5: numeric or keyword?

查看:171
本文介绍了在ElasticSearch 5聚合中最适合使用的数据类型是什么:数字或关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Elasticsearch索引中,我有几个字段正在引用主要类别的ID(例如,sector_id,country_id等)。



这些字段是



仅用于过滤(使用术语/术语过滤器)和创建术语聚合中的存储桶。



其中每个当前都使用最小的合适数值数据类型(例如字节,短等)。



这是用于重型聚合的最佳数据类型吗?



还是应该使用关键字数据类型?



在此先感谢您提供任何建议!

解决方案

如果这些字段的值是数字,则应使用数字类型,如果它们是字符串,则应使用关键字类型。



要记住的一件事是,如果要运行 range 查询和/或<$ c $在某些时候对这些字段进行c> range 聚合时,您应该优先使用数字类型,以便可以对这些值进行数字排序,而不是按词法排序。



例如:如果您有国家ID,例如1、2、3,...,10、11、12,...,20,...,并且它们被映射为关键字(即字符串),则如果您对它们执行范围查询(或汇总),并使用从:1到:3 ,您将也得到11、12、13等,因为在字符串世界中,11在词法上小于3。


In a Elasticsearch index, I have a few fields which are referencing main categories' ids (e.g. sector_id, country_id, etc...).

These fields are solely use for filtering (using the term/terms filters) and for creating buckets in terms aggregations (among others).

Each one of them is currently using the smallest suitable numeric datatype (e.g. byte, short, etc..)

Is this the best datatype to be used on these for heavy aggregations?

Or should these be using the keyword datatype?

Thanks in advance for any advice!

解决方案

If the values of those fields are numeric, you should go for a numeric type, if they are strings, then go for the keyword type.

One thing to bear in mind is that if you want to run range queries and/or range aggregations on those fields at some point, you should prefer using a numeric type up front so that those values can be sorted numerically and not lexically.

For instance: if you have country ids such as 1, 2, 3, ..., 10, 11, 12, ..., 20, ... and they are mapped as keyword (i.e. string) then if you run a range query (or aggregation) on them with from: 1, to: 3, you'll also get 11, 12, 13, etc since in the string world, 11 is lexically smaller than 3.

这篇关于在ElasticSearch 5聚合中最适合使用的数据类型是什么:数字或关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆