Reputation: 3812
On ES6 setup, I have a set of documents with a field named rating which is a string field. The field possible values are 0.5, 1, 2, 3, 4, 5, 6. It is stored as string.
Some sample data:
{
"_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"
}
}
My test query looks like this:
{
"query": {
"match_all": {}
},
"aggs" : {
"rating" : {
"terms" : { "field" : "rating" }
}
}
}
The aggregation result is:
"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
}
]
}
It's very weird as 0.5 seems to be missing from the aggregation result list. I'm very puzzled :(
Upvotes: 0
Views: 26
Reputation: 599
Well, rating is a text field and it looks like it handles the numbers as words. That means that it separates the digits on the dot. If you wish to count the occurances maybe try and do the aggregation on rating.keyword
. That should keep the string together.
Upvotes: 1