Hi,

You should be able to fix your problem by replacing the call to
setAggregations with:

.addAggregation(AggregationBuilders.avg("memory_average").field("MEMORY"))


On Fri, May 23, 2014 at 7:30 PM, Subhadip Bagui <i.ba...@gmail.com> wrote:

> Hi,
>
> I'm trying to do aggregation using java api. But couldn't get the
> *SearchResponse* correctly. Getting below error. I've written method like
> below using XContentBuilder.
> Couldn't get any working scenarios from google. Please suggest any working
> example for aggregation of single value.
>
> * public static Aggregations searchAggregation() throws IOException {*
>
> * Client client = ESClientFactory.getInstance();*
>
> * XContentBuilder contentBuilder = XContentFactory.jsonBuilder()*
>
> * .startObject("aggs").startObject("memory_average")*
>
> * .startObject("avg").field("field", "MEMORY").endObject()*
>
> * .endObject().endObject();*
>
>
> * System.out.println(contentBuilder.string());*
>
> * SearchResponse response = client.prepareSearch("virtualmachines")*
>
> * .setTypes("nodes").setQuery(QueryBuilders.matchAllQuery())*
>
> * .setAggregations(contentBuilder).execute().actionGet();*
>
> * client.close();*
>
> * System.out.println(response);*
>
> * return response.getAggregations();*
>
> * }*
>
> *Error:*
>
> Exception in thread "main"
> *org.elasticsearch.transport.TransportSerializationException*: Failed to
> deserialize exception response from stream
>
>       at
> org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(
> *MessageChannelHandler.java:169*)
>
>       at
> org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(
> *MessageChannelHandler.java:123*)
>
> --
> 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/9c802ccd-1c2d-4d7a-b6f5-c0f045a5097d%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/9c802ccd-1c2d-4d7a-b6f5-c0f045a5097d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adrien Grand

-- 
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/CAL6Z4j5paxw_hxdQLGfjkbJzm0uf2GQ0BbmB7Rh7C_RtKfgqxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to