ElasticSearch Facets术语查询浮点精度(ElasticSearch Facets Terms Query float precision)

编程入门 行业动态 更新时间:2024-10-26 22:27:17
ElasticSearch Facets术语查询浮点精度(ElasticSearch Facets Terms Query float precision)

在使用ElasticSearch 1.7.0查询方面,我遇到了一些问题,所有浮点值都存储在数据库和elasticsearch批量中,但是当我请求数据时,我会得到类似“2.99000000954”的值。

奇怪的是,当我用“2.99000000954”发出请求时,引擎找到了与这个数据相关的好文章,文章的值为“2.99”。

请查看下面的代码文件和curl调用请求:

映射(来自_plugin /头)

"pvi": { "include_in_all": false, "type": "float", "fields": { "raw": { "type": "float" }, "sort": { "type": "float" } } }

elastic_bulk_Article_en_XXX.json0

{ "pvi": [ "2.99" ], }

卷曲电话

curl -XGET 'http://elasticsearch:9200/entrepriseName_search_index_fr_fr/Article/_search' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":[]}},"aggs":{"pvi":{"filter":{"query":{"query_string":{"query":"*","fuzzy_prefix_length":1,"fields":["pvi"]}}},"aggs":{"pvi":{"terms":{"field":"pvi","size":25,"order":{"_term":"asc"}}}}}},"size":0}'

卷曲调用结果

{ "aggregations": { "pvi": { "doc_count": 1007, "pvi": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 1, "doc_count": 1 }, { "key": 2.99000000954, "doc_count": 1 }, { "key": 3.99000000954, "doc_count": 6 }, { "key": 4.98999977112, "doc_count": 33 }, { "key": 5.98999977112, "doc_count": 46 }, { "key": 6.98999977112, "doc_count": 11 }, { "key": 7.98999977112, "doc_count": 69 }, { "key": 9.98999977112, "doc_count": 78 }, { "key": 12.9899997711, "doc_count": 107 }, { "key": 15.9899997711, "doc_count": 135 }, { "key": 17.9899997711, "doc_count": 60 }, { "key": 19.9899997711, "doc_count": 158 }, { "key": 22.9899997711, "doc_count": 17 }, { "key": 25.9899997711, "doc_count": 143 }, { "key": 27.9899997711, "doc_count": 2 }, { "key": 29.9899997711, "doc_count": 70 }, { "key": 35.9900016785, "doc_count": 25 }, { "key": 39, "doc_count": 1 }, { "key": 39.9900016785, "doc_count": 28 }, { "key": 49.9900016785, "doc_count": 12 }, { "key": 59.9900016785, "doc_count": 3 }, { "key": 69.9899978638, "doc_count": 1 } ] } } }, "query": null, "checked": "{}" }

I have some problems with the facets terms query (with ElasticSearch 1.7.0), all float values are right stored in the database and in the elasticsearch bulk too, but when I request the data I get the values like that "2.99000000954".

The strange thing is that when I put my request with "2.99000000954", the engine found the good Article related with this data, the article with the "2.99" value.

Please have a look on the below codes files and the curl call request:

Mapping (from _plugin/head)

"pvi": { "include_in_all": false, "type": "float", "fields": { "raw": { "type": "float" }, "sort": { "type": "float" } } }

elastic_bulk_Article_en_XXX.json0

{ "pvi": [ "2.99" ], }

The curl call

curl -XGET 'http://elasticsearch:9200/entrepriseName_search_index_fr_fr/Article/_search' -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":[]}},"aggs":{"pvi":{"filter":{"query":{"query_string":{"query":"*","fuzzy_prefix_length":1,"fields":["pvi"]}}},"aggs":{"pvi":{"terms":{"field":"pvi","size":25,"order":{"_term":"asc"}}}}}},"size":0}'

The curl call results

{ "aggregations": { "pvi": { "doc_count": 1007, "pvi": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 1, "doc_count": 1 }, { "key": 2.99000000954, "doc_count": 1 }, { "key": 3.99000000954, "doc_count": 6 }, { "key": 4.98999977112, "doc_count": 33 }, { "key": 5.98999977112, "doc_count": 46 }, { "key": 6.98999977112, "doc_count": 11 }, { "key": 7.98999977112, "doc_count": 69 }, { "key": 9.98999977112, "doc_count": 78 }, { "key": 12.9899997711, "doc_count": 107 }, { "key": 15.9899997711, "doc_count": 135 }, { "key": 17.9899997711, "doc_count": 60 }, { "key": 19.9899997711, "doc_count": 158 }, { "key": 22.9899997711, "doc_count": 17 }, { "key": 25.9899997711, "doc_count": 143 }, { "key": 27.9899997711, "doc_count": 2 }, { "key": 29.9899997711, "doc_count": 70 }, { "key": 35.9900016785, "doc_count": 25 }, { "key": 39, "doc_count": 1 }, { "key": 39.9900016785, "doc_count": 28 }, { "key": 49.9900016785, "doc_count": 12 }, { "key": 59.9900016785, "doc_count": 3 }, { "key": 69.9899978638, "doc_count": 1 } ] } } }, "query": null, "checked": "{}" }

最满意答案

我找到了解决方案,我将数据类型从float更改为long,并且一切正常!

I've found the solution, I changed the datatype from float to long and everything works!

更多推荐

本文发布于:2023-08-01 15:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1359310.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浮点   精度   术语   Facets   ElasticSearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!