I have yet to use aggregations (still on facets), so I am making
assumptions here. Your field is a string ("0.03%"), so the average cannot
be computed. Since you pass in a script, you can try doing some string
manipulation, and perhaps converting to a numeric field if it is required.

Something like: doc['CPU_USED'].value.replace("%", "") (not tested)

-- 
Ivan


On Fri, May 23, 2014 at 12:26 AM, Subhadip Bagui <i.ba...@gmail.com> wrote:

> Thanks a lot Ivan. Will try with Java API as u suggested.
>
> One more doubt. There is a field in my document like "CPU_USED": "0.03%"
> Can we do aggregation avg on this field ? I tried but got exception like
> below as this was a string field. Can u please suggest.
>
> "reason": "QueryPhaseExecutionException[[virtualmachines][2]:
> query[filtered(CLOUD_TYPE:cloudstack)->cache(NODE_CREATE_TIME:[1400767895000
> TO 1400769215999])],from[0],size[0]: Query Failed [Failed to execute main
> query]]; nested: AggregationExecutionException[Unsupported script value
> [0.03]]; "
> *Query :*
> POST /virtualmachines/_search
> {
>     "query" : {
>         "filtered" : {
>             "query" : { "match" : {
>               "CLOUD_TYPE" : "CLOUDSTACK"
>             }},
>             "filter" : {
>                 "range" : { "NODE_CREATE_TIME" : { "from" : "2014-05-22
> 14:11:35", "to" : "2014-05-22 14:33:35" }}
>             }
>         }
>     },
>     "aggs" : {
>         "avg_grade" : { "avg" : { "script" : "doc['CPU_USED'].value" } }
>     },
>     "size": 0
> }
>
> --
> 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/bd12c67b-9369-4231-90ec-a818a6e9be9a%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/bd12c67b-9369-4231-90ec-a818a6e9be9a%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/CALY%3DcQAM%2BxOoXFRRs59WdLHYfa0P0RjOnuXZp1a1VPpa_qgjQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to