Skip to content

PutScript API does not accept mustache search template objects in StoredScript #876

Closed
@jbaiera

Description

@jbaiera

The PutScript API supports scripts in string format and mustache search templates in json object format. These options are detailed in the API Docs.

The existing generated code for StoredScript only accepts string data for the script source. This makes it impossible for the client to create or update search templates written in mustache.

PutScriptResponse response = elasticsearchClient.putScript(req -> req
            .id(entry.getKey())
            .script(s -> s
                        .source(...)) // Only accepts string data
);

If trying to read in a valid script request body there are parsing errors:

{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "match": {
          "all": {
            "query": "{{query_string}}"
          }
        }
      }
    }
  }
}
Reader scriptJson = ...
PutScriptResponse response = elasticsearchClient.putScript(req -> req
        .id(entry.getKey())
        .withJson(scriptJson)
);
Exception in thread "main" co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.StoredScript: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_OBJECT' instead of '[KEY_NAME, VALUE_STRING, VALUE_NUMBER, VALUE_TRUE, VALUE_FALSE]' (JSON path: script.source) (line no=4, column no=16, offset=55)
	at co.elastic.clients.json.JsonpMappingException.from0(JsonpMappingException.java:134)
	at co.elastic.clients.json.JsonpMappingException.from(JsonpMappingException.java:121)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:218)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:148)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:77)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:192)
	at co.elastic.clients.util.WithJsonObjectBuilderBase.withJson(WithJsonObjectBuilderBase.java:54)
	at co.elastic.clients.json.WithJson.withJson(WithJson.java:57)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.putScript(ElasticsearchClient.java:1641)
Caused by: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_OBJECT' instead of '[KEY_NAME, VALUE_STRING, VALUE_NUMBER, VALUE_TRUE, VALUE_FALSE]'
	at co.elastic.clients.json.JsonpUtils.ensureAccepts(JsonpUtils.java:117)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:76)
	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:192)
	... 13 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SpecificationRelated to the API spec used to generate client codeCategory: BugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions