聚合的奇怪问题(数字被四舍五入?)

时间:2018-02-06 11:22:06

标签: elasticsearch

在ES6设置中,我有一组文档,其中包含一个名为rating的字段,它是一个字符串字段。字段可能的值为0.5,1,2,3,4,5,6。它存储为字符串。

一些示例数据:

            {
                "_index": "extension_11",
                "_type": "extension_11",
                "_id": "96731bbaae8646189fc0ff2bfd262d92_13",
                "_score": 1,
                "_source": {
                    "id": 13,
                    "extension": 11,
                    "rating": "0.5",
                    "enabled": true,
                    "destination": 16,
                    "place": 24,
                    "_meta": {
                        "resource": "extension.entity.accommodation",
                        "path": "accommodation",
                        "sluggable": true,
                        "url": "http://localhost/accommodation/amankora-bumthang"
                    },
                    "slug": "amankora-bumthang",
                    "identifier": "96731bbaae8646189fc0ff2bfd262d92"
                }
            },
            {
                "_index": "extension_11",
                "_type": "extension_11",
                "_id": "96731bbaae8646189fc0ff2bfd262d92_14",
                "_score": 1,
                "_source": {
                    "id": 14,
                    "extension": 11,
                    "rating": "0.5",
                    "enabled": null,
                    "destination": 16,
                    "place": 22,
                    "_meta": {
                        "resource": "extension.entity.accommodation",
                        "path": "accommodation",
                        "sluggable": true,
                        "url": "http://localhost/accommodation/bhutan-mandala-resort"
                    },
                    "slug": "bhutan-mandala-resort",
                    "identifier": "96731bbaae8646189fc0ff2bfd262d92"
                }
            }

我的测试查询如下所示:

{
    "query": {
        "match_all": {}
    },
    "aggs" : {
        "rating" : {
            "terms" : { "field" : "rating" }
        }
    }
}

汇总结果为:

"rating": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": 0,
                    "doc_count": 86
                },
                {
                    "key": 3,
                    "doc_count": 62
                },
                {
                    "key": 5,
                    "doc_count": 39
                },
                {
                    "key": 4,
                    "doc_count": 38
                },
                {
                    "key": 2,
                    "doc_count": 20
                },
                {
                    "key": 6,
                    "doc_count": 1
                }
            ]
        }

非常奇怪,因为聚合结果列表中似乎缺少0.5。我非常困惑:(

1 个答案:

答案 0 :(得分:1)

好吧,评级是一个文本字段,看起来它将数字作为单词处理。这意味着它会分离点上的数字。如果您希望计算出现次数,可以尝试在{ TShardProcessThread for use when calling from child thread. } constructor TSharedProcessThread.Create(AProc: TSharedProcessThread); begin FProc := AProc; FProc.Thread := Self; inherited; end; procedure TShardProcessThread.Execute(); begin FProc.Run(); end; { Main thread creates child thread } begin { Keep reference to FProc because it can only be destroyed after thread terminates. TIP: Safest would be to use a reference counted interface. } FProc := TSharedProcess.Create(...); try LThread := TShardProcessThread.Create(FProc); LThread.OnTerminate := HandleThreadTerminate; except { Exception in thread create means thread will not run and will not terminate; so free object immediately. } FProc.Free; raise; end; end; 上进行聚合。这应该将字符串保持在一起。

相关问题