# Unable to return SearchResponse with aggregations Java High Level REST Client

**URL:** <https://discuss.elastic.co/t/unable-to-return-searchresponse-with-aggregations-java-high-level-rest-client/166448>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 11:56pm UTC](https://discuss.elastic.co/t/unable-to-return-searchresponse-with-aggregations-java-high-level-rest-client/166448 "2019-01-30T23:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Giles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luke_giles/32/51893_2.png) [@Luke\_Giles](https://discuss.elastic.co/u/Luke_Giles)\
**Post date:** [January 30, 2019, 11:56pm UTC](https://discuss.elastic.co/t/unable-to-return-searchresponse-with-aggregations-java-high-level-rest-client/166448/1 "2019-01-30T23:56:48Z")

</div>

Hi all,

I'm trying to using the Java High Level REST Client API to return a SearchResponse from a search template using aggregates and getting the following error;

```
`Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: For input string: "House" (through reference chain: org.elasticsearch.action.search.SearchResponse["aggregations"]->org.elasticsearch.search.aggregations.Aggregations["asMap"]->java.util.Collections$UnmodifiableMap["land_use_search"]->org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter["aggregations"]->org.elasticsearch.search.aggregations.Aggregations["asMap"]->java.util.Collections$UnmodifiableMap["land_use"]->org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms["buckets"]->java.util.ArrayList[0]->org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms$ParsedBucket["keyAsNumber"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: For input string: "Accounting / Auditing And Bookkeeping" (through reference chain: org.elasticsearch.action.search.SearchResponse["aggregations"]->org.elasticsearch.search.aggregations.Aggregations["asMap"]->java.util.Collections$UnmodifiableMap["land_use_search"]->org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter["aggregations"]->org.elasticsearch.search.aggregations.Aggregations["asMap"]->java.util.Collections$UnmodifiableMap["land_use"]->org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms["buckets"]->java.util.ArrayList[0]->org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms$ParsedBucket["keyAsNumber"])
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)`

```

Search Template

```
    {
  "script": {
    "lang": "mustache",
    "source": {
      "size": "0",
      "aggs": {
        "land_use_search": {
          "filter": {
            "wildcard": {
              "land_use_desc.keyword": "*{{searchTerm}}*"
            }
          },
          "aggs": {
            "land_use": {
              "terms": {
                "field": "land_use_desc.keyword",
                "order" : {"_key" : "asc"},
                "size": 1000
              }
            }
          }
        }
      }
    }
  }
}

```

Mapping for field;

```
  "land_use_desc": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }

```

Java Client calling template  
`elasticSearch.client().searchTemplate(request, RequestOptions.DEFAULT).getResponse();`

It looks as though the response is expecting the key for the results to be a number, where it is valid for it to be a String?

Any help would be appreciated.

Thanks,  
Luke

---

<div class="post-metadata">

**Author:** ![Luke\_Giles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luke_giles/32/51893_2.png) [@Luke\_Giles](https://discuss.elastic.co/u/Luke_Giles)\
**Post date:** [January 31, 2019, 10:59pm UTC](https://discuss.elastic.co/t/unable-to-return-searchresponse-with-aggregations-java-high-level-rest-client/166448/2 "2019-01-31T22:59:45Z")

</div>

UPDATE:

I have found the same issue on [https://stackoverflow.com/questions/47792915/getting-jackson-parsing-error-while-serializing-aggregatedpage-in-spring-data-el](https://stackoverflow.com/questions/47792915/getting-jackson-parsing-error-while-serializing-aggregatedpage-in-spring-data-el)

The fix on this page though does seem a lot more like a workaround rather than a solution, so if anyone has a proposed solution that would be still be great.

Thanks,  
Luke

---

<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:** [February 28, 2019, 11:00pm UTC](https://discuss.elastic.co/t/unable-to-return-searchresponse-with-aggregations-java-high-level-rest-client/166448/3 "2019-02-28T23:00:04Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
