Besides the Terms filter in aggregation , you should use range aggregation .
It would work like..

{
  "aggs": {
    stars" : {
       "range" : {
              "field" : "starRating" ,
             "ranges": [{
                                "to": 5
                            }, {
                                "from": 5,
                                "to": 10
                            }, {
                                "from": 10,
                                "to": 15
                            }, {
                                "from": 15
                            }]

           }
    }
}



On Mon, Apr 27, 2015 at 4:18 PM, <r...@hubrick.com> wrote:

> Hey,
>
> I'm a little bit stucked using Terms aggregations on a numeric field.
>
> My schema looks like that:
>
> { ...
>    starRating:
>    {
>
>    -   type: "long"
>
>    }
> ...
> }
>
> I pass documents there, works fine.
> I query them, using a Range Query like, works also fine:
>
> {
>   "range": {
>     "starRating": {
>       "from": 0,
>       "to": 5,
>     }
>   }
> }
>
> Whenever I ask for Term Aggregations like:
>
> {
>   "aggs": {
>     stars" : {
>        "terms" : { "field" : "starRating" }
>     }
> }
>
> OR Facets with
>
>   "facets" : {
>     "tag" : {
>       "terms" : {
>         "field" : "starRating"
>       }
>     }
>   }
>
> Strange values are returned:
>
> "facets": {
>     "tag": {
>       "_type": "terms",
>       "missing": 0,
>       "total": 3814,
>       "other": 0,
>       "terms": [
>         {
>           "term": 0.0,
>           "count": 2397
>         },
>         {
>           "term": 1.5E-323,
>           "count": 610
>         },
>         {
>           "term": 2.0E-323,
>           "count": 378
>         },
>         {
>           "term": 1.0E-323,
>           "count": 269
>         },
>         {
>           "term": 4.9E-324,
>           "count": 93
>         },
>         {
>           "term": 2.5E-323,
>           "count": 67
>         }
>       ]
>     }
>   },
>   "aggregations": {
>     "stars": {
>       "doc_count_error_upper_bound": 0,
>       "sum_other_doc_count": 0,
>       "buckets": [
>         {
>           "key": 0.0,
>           "doc_count": 2397
>         },
>         {
>           "key": 1.5E-323,
>           "doc_count": 610
>         },
>         {
>           "key": 2.0E-323,
>           "doc_count": 378
>         },
>         {
>           "key": 1.0E-323,
>           "doc_count": 269
>         },
>         {
>           "key": 4.9E-324,
>           "doc_count": 93
>         },
>         {
>           "key": 2.5E-323,
>           "doc_count": 67
>         }
>       ]
>     }
>   }
>
>
> Even in the Java Client, I get DoubleTerms instead of LongTerms.
>
> Does anybody have an Idea, what wents wrong there. I would expect
> Long-Keys and not Double keys (which are basically close to 0)
> The Histogram (with interval of 1) also does not work, everything is close
> to the zero valued key.
>
>
> Cheers, Ralf
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elasticsearch+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/7c604a6a-aaf8-4645-903b-d9472868b1bd%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/7c604a6a-aaf8-4645-903b-d9472868b1bd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAHzCMprJiRGLs50K9o1OfdWYA65-RNFOmF-gWCOQTtSo2UB8Wg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to