# Java API and aggregations result problem

**URL:** <https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835>\
**Category:** Elasticsearch\
**Created:** [September 17, 2014, 9:57am UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835 "2014-09-17T09:57:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpouget](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@lpouget](https://discuss.elastic.co/u/lpouget)\
**Post date:** [September 17, 2014, 9:57am UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835/1 "2014-09-17T09:57:20Z")

</div>

I have a problem with Java API and aggregations result

Serializer (jackson) produce this error:

No serializer found for class org.elasticsearch.common.text.StringText and  
no properties discovered to create BeanSerializer

for this query :

1. {
2. 

```
"size": 0,

```

3. 

```
"aggregations": {

```

4. 

```
    "agg": {

```

5. 

```
        "global": {},

```

6. 

```
        "aggregations": {

```

7. 

```
            "dim-1": {

```

8. 

```
                "terms": {

```

9. 

```
                    "field": "field-1"

```

10. 

```
                },

```

11. 

```
                "aggregations": {

```

12. 

```
                    "dim-2": {

```

13. 

```
                        "terms": {

```

14. 

```
                            "field": "field-2"

```

15. 

```
                        },

```

16. 

```
                        "aggregations": {

```

17. 

```
                            "myStats": {

```

18. 

```
                                "stats": {

```

19. 

```
                                    "field": "statsField"

```

20. 

```
                                }

```

21. 

```
                            }

```

22. 

```
                        }

```

23. 

```
                    }

```

24. 

```
                }

```

25. 

```
            }

```

26. 

```
        }

```

27. 

```
    }

```

28. 

```
}

```

29. }

with this response :

1. {
2. "took":15932,
3. "timed\_out":false,
4. "\_shards":{
5. 

```
  "total":2,

```

6. 

```
  "successful":2,

```

7. 

```
  "failed":0

```

8. },
9. "hits":{
10. 

```
  "total":38376901,

```

11. 

```
  "max_score":0,

```

12. 

```
  "hits":[

```

13. 
14. 

```
  ]

```

15. },
16. "aggregations":{
17. 

```
  "agg":{

```

18. 

```
     "doc_count":38376901,

```

19. 

```
     "dim-1":{

```

20. 

```
        "buckets":[

```

21. 

```
           {

```

22. 

```
              "key":27380,

```

23. 

```
              "doc_count":311352,

```

24. 

```
              "dim-2":{

```

25. 

```
                 "buckets":[

```

26. 

```
                    {

```

27. 

```
                       "key":1,

```

28. 

```
                       "doc_count":275581,

```

29. 

```
                       "statsField":{

```

30. 

```
                          "count":275581,

```

31. 

```
                          "min":245,

```

32. 

```
                          "max":1295001,

```

33. 

```
                          "avg":111170.57729999075,

```

34. 

```
                          "sum":30636498862.908752

```

35. 

```
                       }

```

36. 

```
                    },

```

37. 

```
                    {

```

38. 

```
                       "key":2,

```

39. 

```
                       "doc_count":35771,

```

40. 

```
                       "statsField":{

```

41. 

```
                          "count":35771,

```

42. 

```
                          "min":300,

```

43. 

```
                          "max":2070000,

```

44. 

```
                          "avg":288086.52814757434,

```

45. 

```
                          "sum":10305143198.366882

```

46. 

```
                       }

```

47. 

```
                    }

```

48. 

```
                 ]

```

49. 

```
              }

```

50. 

```
           },

```

51. 

```
           {

```

52. 

```
              "key":1595,

```

53. 

```
              "doc_count":269090,

```

54. 

```
              "dim-2":{

```

55. 

```
                 "buckets":[

```

56. 

```
                    {

```

57. 

```
                       "key":1,

```

58. 

```
                       "doc_count":221705,

```

59. 

```
                       "statsField":{

```

60. 

```
                          "count":221705,

```

61. 

```
                          "min":180,

```

62. 

```
                          "max":3450000,

```

63. 

```
                          "avg":69082.0294308078,

```

64. 

```
                          "sum":15315831334.957245

```

65. 

```
                       }

```

66. 

```
                    },

```

67. 

```
                    {

```

68. 

```
                       "key":2,

```

69. 

```
                       "doc_count":47385,

```

70. 

```
                       "statsField":{

```

71. 

```
                          "count":47385,

```

72. 

```
                          "min":250,

```

73. 

```
                          "max":6000000,

```

74. 

```
                          "avg":298778.0619758563,

```

75. 

```
                          "sum":14157598466.725952

```

76. 

```
                       }

```

77. 

```
                    }

```

78. 

```
                 ]

```

79. 

```
              }

```

80. 

```
           }

```

81. 

```
        ]

```

82. 

```
     }

```

83. 

```
  }

```

84. }
85. }

How can I successfully serialize aggregations result ?

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/61d79a3a-6fcd-458a-8e24-76e25ac4810d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/61d79a3a-6fcd-458a-8e24-76e25ac4810d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 17, 2014, 1:53pm UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835/2 "2014-09-17T13:53:39Z")

</div>

Why don't you use Java client?

If you are using it why do you need to convert JSON responses to elasticsearch objects?  
I don't understand exactly what you are trying to do here.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 17 septembre 2014 à 11:57:24, [lpouget@yanport.com](mailto:lpouget@yanport.com) ([lpouget@yanport.com](mailto:lpouget@yanport.com)) a écrit:

I have a problem with Java API and aggregations result

Serializer (jackson) produce this error:  
No serializer found for class org.elasticsearch.common.text.StringText and no properties discovered to create BeanSerializer

for this query :

{  
"size": 0,  
"aggregations": {  
"agg": {  
"global": {},  
"aggregations": {  
"dim-1": {  
"terms": {  
"field": "field-1"  
},  
"aggregations": {  
"dim-2": {  
"terms": {  
"field": "field-2"  
},  
"aggregations": {  
"myStats": {  
"stats": {  
"field": "statsField"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

with this response :

{  
"took":15932,  
"timed\_out":false,  
"\_shards":{  
"total":2,  
"successful":2,  
"failed":0  
},  
"hits":{  
"total":38376901,  
"max\_score":0,  
"hits":[

```
  ]

```

},  
"aggregations":{  
"agg":{  
"doc\_count":38376901,  
"dim-1":{  
"buckets":[  
{  
"key":27380,  
"doc\_count":311352,  
"dim-2":{  
"buckets":[  
{  
"key":1,  
"doc\_count":275581,  
"statsField":{  
"count":275581,  
"min":245,  
"max":1295001,  
"avg":111170.57729999075,  
"sum":30636498862.908752  
}  
},  
{  
"key":2,  
"doc\_count":35771,  
"statsField":{  
"count":35771,  
"min":300,  
"max":2070000,  
"avg":288086.52814757434,  
"sum":10305143198.366882  
}  
}  
]  
}  
},  
{  
"key":1595,  
"doc\_count":269090,  
"dim-2":{  
"buckets":[  
{  
"key":1,  
"doc\_count":221705,  
"statsField":{  
"count":221705,  
"min":180,  
"max":3450000,  
"avg":69082.0294308078,  
"sum":15315831334.957245  
}  
},  
{  
"key":2,  
"doc\_count":47385,  
"statsField":{  
"count":47385,  
"min":250,  
"max":6000000,  
"avg":298778.0619758563,  
"sum":14157598466.725952  
}  
}  
]  
}  
}  
]  
}  
}  
}  
}

How can I successfully serialize aggregations result ?

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/61d79a3a-6fcd-458a-8e24-76e25ac4810d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/61d79a3a-6fcd-458a-8e24-76e25ac4810d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.54199263.6590700b.3c6%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.54199263.6590700b.3c6%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![lpouget](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@lpouget](https://discuss.elastic.co/u/lpouget)\
**Post date:** [September 17, 2014, 3:01pm UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835/3 "2014-09-17T15:01:36Z")

</div>

I am using Java client.  
I wanted to convert elasticsearch objects to JSON responses. The JSON  
result above was the expected result.

I successfully convert it with Jackson by  
switching SerializationFeature.FAIL\_ON\_EMPTY\_BEANS to false which seems  
mandatory to serialize aggregation elasticsearch objects.

Sorry, my question wasn't clear.

On Wednesday, September 17, 2014 3:53:58 PM UTC+2, David Pilato wrote:

> Why don't you use Java client?
> 
> If you are using it why do you need to convert JSON responses to  
> elasticsearch objects?  
> I don't understand exactly what you are trying to do here.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 17 septembre 2014 à 11:57:24, [lpo...@yanport.com](mailto:lpo...@yanport.com) \<javascript:\> (  
> [lpo...@yanport.com](mailto:lpo...@yanport.com) \<javascript:\>) a écrit:
> 
> I have a problem with Java API and aggregations result
> 
> Serializer (jackson) produce this error:
> 
> No serializer found for class org.elasticsearch.common.text.StringText  
> and no properties discovered to create BeanSerializer
> 
> for this query :
> 
> 1. {  
> 2. "size": 0,  
> 3. "aggregations": {  
> 4. "agg": {  
> 5. "global": {},  
> 6. "aggregations": {  
> 7. "dim-1": {  
> 8. "terms": {  
> 9. "field": "field-1"  
> 10. },  
> 11. "aggregations": {  
> 12. "dim-2": {  
> 13. "terms": {  
> 14. "field": "field-2"  
> 15. },  
> 16. "aggregations": {  
> 17. "myStats": {  
> 18. "stats": {  
> 19. "field": "statsField"  
> 20. }  
> 21. }  
> 22. }  
> 23. }  
> 24. }  
> 25. }  
> 26. }  
> 27. }  
> 28. }  
> 29. }
> 
> with this response :
> 
> 1. {  
> 2. "took":15932,  
> 3. "timed\_out":false,  
> 4. "\_shards":{  
> 5. "total":2,  
> 6. "successful":2,  
> 7. "failed":0  
> 8. },  
> 9. "hits":{  
> 10. "total":38376901,  
> 11. "max\_score":0,  
> 12. "hits":[  
> 13.  
> 14. ]  
> 15. },  
> 16. "aggregations":{  
> 17. "agg":{  
> 18. "doc\_count":38376901,  
> 19. "dim-1":{  
> 20. "buckets":[  
> 21. {  
> 22. "key":27380,  
> 23. "doc\_count":311352,  
> 24. "dim-2":{  
> 25. "buckets":[  
> 26. {  
> 27. "key":1,  
> 28. "doc\_count":275581,  
> 29. "statsField":{  
> 30. "count":275581,  
> 31. "min":245,  
> 32. "max":1295001,  
> 33. "avg":111170.57729999075,  
> 34. "sum":30636498862.908752  
> 35. }  
> 36. },  
> 37. {  
> 38. "key":2,  
> 39. "doc\_count":35771,  
> 40. "statsField":{  
> 41. "count":35771,  
> 42. "min":300,  
> 43. "max":2070000,  
> 44. \<div class="de2" style="-webkit-user-select: text; padding-right:  
> 5px; padding-left: 5px; vertical-align: top; color: rgb(0, 0, 0);  
> border-left-width: 1px; border-left-style: solid; border-left-color:  
> rgb(204, 204, 204); margin-left: -7px; position: relative; line-height:  
> 21px; backgrou
> 
> ...

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/445d7b7f-fe03-4df3-87f4-fbe54b058c62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/445d7b7f-fe03-4df3-87f4-fbe54b058c62%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 17, 2014, 3:05pm UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835/4 "2014-09-17T15:05:21Z")

</div>

I think that if you do

SearchResponse response = esClient.prepareSearch("person")  
.setTypes("person")  
.addAggregation(  
AggregationBuilders.terms("by\_country").field("country")  
)  
.execute().actionGet();

logger.trace("elasticsearch response: {}", response.toString());

You will have directly the JSON response.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 17 septembre 2014 à 17:01:41, [lpouget@yanport.com](mailto:lpouget@yanport.com) ([lpouget@yanport.com](mailto:lpouget@yanport.com)) a écrit:

I am using Java client.  
I wanted to convert elasticsearch objects to JSON responses. The JSON result above was the expected result.

I successfully convert it with Jackson by switching SerializationFeature.FAIL\_ON\_EMPTY\_BEANS to false which seems mandatory to serialize aggregation elasticsearch objects.

Sorry, my question wasn't clear.

On Wednesday, September 17, 2014 3:53:58 PM UTC+2, David Pilato wrote:  
Why don't you use Java client?

If you are using it why do you need to convert JSON responses to elasticsearch objects?  
I don't understand exactly what you are trying to do here.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 17 septembre 2014 à 11:57:24, [lpo...@yanport.com](mailto:lpo...@yanport.com) ([lpo...@yanport.com](mailto:lpo...@yanport.com)) a écrit:

I have a problem with Java API and aggregations result

Serializer (jackson) produce this error:  
No serializer found for class org.elasticsearch.common.text.StringText and no properties discovered to create BeanSerializer

for this query :

{  
"size": 0,  
"aggregations": {  
"agg": {  
"global": {},  
"aggregations": {  
"dim-1": {  
"terms": {  
"field": "field-1"  
},  
"aggregations": {  
"dim-2": {  
"terms": {  
"field": "field-2"  
},  
"aggregations": {  
"myStats": {  
"stats": {  
"field": "statsField"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

with this response :

{  
"took":15932,  
"timed\_out":false,  
"\_shards":{  
"total":2,  
"successful":2,  
"failed":0  
},  
"hits":{  
"total":38376901,  
"max\_score":0,  
"hits":[

```
  ]

```

},  
"aggregations":{  
"agg":{  
"doc\_count":38376901,  
"dim-1":{  
"buckets":[  
{  
"key":27380,  
"doc\_count":311352,  
"dim-2":{  
"buckets":[  
{  
"key":1,  
"doc\_count":275581,  
"statsField":{  
"count":275581,  
"min":245,  
"max":1295001,  
"avg":111170.57729999075,  
"sum":30636498862.908752  
}  
},  
{  
"key":2,  
"doc\_count":35771,  
"statsField":{  
"count":35771,  
"min":300,  
"max":2070000,

## \<div class="de2" style="-webkit-user-select: text; padding-right: 5px; padding-left: 5px; vertical-align: top; color: rgb(0, 0, 0); border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-left: -7px; position: relative; line-height: 21px; backgrou ...

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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/445d7b7f-fe03-4df3-87f4-fbe54b058c62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/445d7b7f-fe03-4df3-87f4-fbe54b058c62%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.5419a331.6b94764.3c6%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5419a331.6b94764.3c6%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:01am UTC](https://discuss.elastic.co/t/java-api-and-aggregations-result-problem/19835/5 "2017-07-06T01:01:32Z")

</div>


