Unable to return SearchResponse with aggregations Java High Level REST Client

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

UPDATE:

I have found the same issue on 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

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