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
Closed

Aggregations: Histogram Aggregation key Bug #6655

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

Comments

@rnonnon-ebiz
Copy link

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
Copy link
Contributor

jpountz 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
Copy link
Contributor

uboness 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
Copy link
Author

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
Copy link

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
Copy link
Author

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 added a commit that referenced this issue Jul 16, 2014
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
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
@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
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants