Elasticsearch“数据”:{“类型”:“浮动”; } 查询返回不正确的结果
我有一个如下查询,当 date_partition 字段为“type”=> “float”它返回诸如 20220109、20220108、20220107 之类的查询。 当字段“类型”=> “long”,它只返回20220109查询。这就是我想要的。
下面的每个查询都会返回结果,就像发送了查询 20220119 一样。 --> 20220109、20220108、20220107
PUT date
{
"mappings": {
"properties": {
"date_partition_float": {
"type": "float"
},
"date_partition_long": {
"type": "long"
}
}
}
}
POST date/_doc
{
"date_partition_float": "20220109",
"date_partition_long": "20220109"
}
#its return the query
GET date/_search
{
"query": {
"match": {
"date_partition_float": "20220108"
}
}
}
#nothing return
GET date/_search
{
"query": {
"match": {
"date_partition_long": "20220108"
}
}
}
这是一个错误还是 float 类型的工作原理? 加载到 Elasticsearch 的 2 年数据(例如第 1 天、第 2 天)(每天 20 GB pri 分片大小)(总计 15 TB)更改此字段类型的最佳方法是什么? 我的映射中有 5 个浮点类型,更改所有浮点类型的最快方法是什么。 注意:在我看来,我有以下解决方案,但恐怕
I have a query like below and when date_partition field is "type" => "float" it returns queries like 20220109, 20220108, 20220107.
When field "type" => "long", it only returns 20220109 query. Which is what I want.
Each queries below, the result is returned as if the query 20220119 was sent.
--> 20220109, 20220108, 20220107
PUT date
{
"mappings": {
"properties": {
"date_partition_float": {
"type": "float"
},
"date_partition_long": {
"type": "long"
}
}
}
}
POST date/_doc
{
"date_partition_float": "20220109",
"date_partition_long": "20220109"
}
#its return the query
GET date/_search
{
"query": {
"match": {
"date_partition_float": "20220108"
}
}
}
#nothing return
GET date/_search
{
"query": {
"match": {
"date_partition_long": "20220108"
}
}
}
Is this a bug or is this how float type works ?
2 years of data loaded to Elasticsearch (like day-1, day-2) (20 gb pri shard size per day)(total 15 TB) what is the best way to change the type of just this field ?
I have 5 float type in my mapping, what is the fastest way to change all of them.
Note: In my mind I have below solutions but I'm afraid it's slow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该
date_partition
字段应具有date
类型和format=yyyyMMdd
,这是唯一可以使用的合理类型,而不是long
甚至更糟糕的浮动
。查询
20220108
并在结果中返回20220109
文档是不合逻辑的。使用
date
类型还允许您使用适当的基于时间的range
查询并在数据上创建date_histogram
聚合。您可以使用适当的类型重新创建索引并重新索引数据,或者向现有索引添加新字段并通过查询更新它。两个选项都有效。
That
date_partition
field should have thedate
type withformat=yyyyMMdd
, that's the only sensible type to use, notlong
and even worsefloat
.It's not logical to query for
20220108
and have the20220109
document returned in the results.Using the
date
type would also allow you to use proper time-basedrange
queries and createdate_histogram
aggregations on your data.You can either recreate the index with the adequate type and reindex your data, or add a new field to your existing index and update it by query. Both options are valid.
这是我的问题的答案=> https://discuss.elastic.co/ t/elasticsearch-data-type-float-returns-in Correct-results/300335
Here is the answer to my question => https://discuss.elastic.co/t/elasticsearch-data-type-float-returns-incorrect-results/300335