ElasticSearch keyword mapping leads to illegal_state_exception

In a spring boot application when indexing an object into es I get the following exception.

Suppressed: org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9299], 
URI [/my_index_name/_doc/1000001_000000004-v2?timeout=5s], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [billingperiod] 
of type [keyword] in document with id '1000001_000000004-v2'. Preview of field's value: 
'{enddate=2016-12-31, startdate=2016-10-01}'"}],"type":"mapper_parsing_exception","reason":"failed to 
parse field [billingperiod] of type [keyword] in document with id '1000001_000000004-v2'. Preview of 
field's value: '{enddate=2016-12-31, startdate=2016-10-01}'","caused_by":{"type":"illegal_state_exception",
"reason":"Can't get text on a START_OBJECT at 1:399"}},"status":400}
    at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:318)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:262)
    at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1628)
    ... 133 common frames omitted
Caused by: org.elasticsearch.ElasticsearchException: 
Elasticsearch exception [type=illegal_state_exception, reason=Can't get text on a START_OBJECT at 1:399]
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:496)
at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:407)
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:437)
at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:603)
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:179)
... 136 common frames omitted

The class has a couple of static fields and two instance variables of type LocalDate and a view methods one of which is the overridden toString.

The mapping is as follows. Without the mapping the indexing works fine. However, a null_value needs to be configured since the object can be null.

    {
      "dynamic_templates": [
        {
          "mapStringToKeywordByDefault": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword"
            }
          }
        }
      ],
      "properties": {
        "billingperiod": {
          "type": "keyword",
          "null_value": "anemptystring"
        }
      }
    }

I tried to replace keyword with flattened , however, the docs state: "A string value which is substituted for any explicit null values within the flattened object field. Defaults to null, which means null sields are treated as if it were missing." So if the object itself is null it is not working.

Without any mapping there is no problem. However, shouldn't the default be keyword anyway?

Version Elasticsearch 7.10 (cannot be changed)

What is my mistake? What can I do to make that work?

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