Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregations: Histogram Aggregation key Bug #6655

Closed
rnonnon-ebiz opened this Issue Jun 30, 2014 · 5 comments

Comments

Projects
None yet
6 participants
@rnonnon-ebiz
Copy link

commented Jun 30, 2014

Hi,

I'm working with histogram aggregation but there is something strange with keys.
For instance (cf : http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html):

If I use this request :

{
    "aggs" : {
        "prices" : {
            "histogram" : {
                "field" : "price",
                "interval" : 50
            }
        }
    }
}

I obtain something like this :

{
    "aggregations": {
        "prices" : {
            "buckets": [
                {
                    "key_as_string" : "0",
                    "key": 0,
                    "doc_count": 2
                },
                {
                    "key_as_string" : "50",
                    "key": 50,
                    "doc_count": 4
                },
                {
                    "key_as_string" : "150",
                    "key": 150,
                    "doc_count": 3
                }
            ]
        }
    }
}

Instead of :

{
    "aggregations": {
        "prices" : {
            "buckets": [
                {
                    "key": 0,
                    "doc_count": 2
                },
                {
                    "key": 50,
                    "doc_count": 4
                },
                {
                    "key": 150,
                    "doc_count": 3
                }
            ]
        }
    }
}

You could say, it's not important but it generates json ~1/3 bigger...
Is there a mean to disable this ???

Moreover, in Elasticsearch Java API, it could be fine to have a method to request the response as a hash instead keyed by the buckets keys (cf :http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#_response_format)

Thanks!!!

@jpountz

This comment has been minimized.

Copy link
Contributor

commented Jun 30, 2014

There is currently no way to disable key_as_string.

Moreover, in Elasticsearch Java API, it could be fine to have a method to request the response as a hash instead keyed by the buckets keys

I am not sure to get what you mean. The Java API already has hash-like access to the buckets via the getBucketByKey method, is it what you are looking for?

@jpountz jpountz self-assigned this Jun 30, 2014

@uboness

This comment has been minimized.

Copy link
Contributor

commented Jul 1, 2014

this is a bug... the key_as_string should only be there if format is explicitly specified (like in all other aggs)

@rnonnon-ebiz

This comment has been minimized.

Copy link
Author

commented Jul 1, 2014

Thanks jpountz for having format my post ;)
Thanks both for your answers.

I meant it's not possible to ask ES for a JSON like this :

{
    "aggregations": {
        "prices": {
            "buckets": {
                "0": {
                    "key": 0,
                    "doc_count": 2
                },
                "50": {
                    "key": 50,
                    "doc_count": 4
                },
                "150": {
                    "key": 150,
                    "doc_count": 3
                }
            }
        }
    }
}

Yes it's possible to access the Json with getBucketByKey but the JSON is like this :

{
    "aggregations": {
        "prices" : {
            "buckets": [
                {
                    "key_as_string" : "0",
                    "key": 0,
                    "doc_count": 2
                },
                {
                    "key_as_string" : "50",
                    "key": 50,
                    "doc_count": 4
                },
                {
                    "key_as_string" : "150",
                    "key": 150,
                    "doc_count": 3
                }
            ]
        }
    }
}

Furthermore if it's a bug, why close that post?

@clintongormley

This comment has been minimized.

Copy link
Member

commented Jul 1, 2014

Furthermore if it's a bug, why close that post?

Because this post is still open, and the closed post is a duplicate.

@rnonnon-ebiz

This comment has been minimized.

Copy link
Author

commented Jul 1, 2014

Oups... My Bad.... :s
Sorry

@colings86 colings86 assigned colings86 and unassigned jpountz Jul 11, 2014

@colings86 colings86 added v1.3.0 and removed adoptme labels Jul 11, 2014

@s1monw s1monw added v1.4.0 and removed v1.3.0 labels Jul 14, 2014

@colings86 colings86 closed this in 8260138 Jul 16, 2014

colings86 added a commit that referenced this issue Jul 16, 2014

Aggregations: Fixed Histogram key_as_string bug
The key as string field in the response for the histogram aggregation will now only show if format is specified on the request.

Closes #6655

colings86 added a commit that referenced this issue Jul 16, 2014

Aggregations: Fixed Histogram key_as_string bug
The key as string field in the response for the histogram aggregation will now only show if format is specified on the request.

Closes #6655

@colings86 colings86 added the v1.3.0 label Jul 16, 2014

@clintongormley clintongormley changed the title Histogram Aggregation key Bug Aggregations: Histogram Aggregation key Bug Jul 16, 2014

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Aggregations: Fixed Histogram key_as_string bug
The key as string field in the response for the histogram aggregation will now only show if format is specified on the request.

Closes elastic#6655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.