Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jbaiera opened this issue Aug 30, 2024 · 2 comments
Closed
Labels
Area: Specification Related to the API spec used to generate client code Category: Bug Something isn't working

Comments

@jbaiera
Copy link
Member

jbaiera commented Aug 30, 2024

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
@jbaiera jbaiera added Area: Specification Related to the API spec used to generate client code Category: Bug Something isn't working labels Aug 30, 2024
@l-trotta
Copy link
Contributor

l-trotta commented Sep 2, 2024

Hello, thank you for reporting this! It will be fixed.

@l-trotta
Copy link
Contributor

fixed it in elastic/elasticsearch-specification#2960, will be part of the next major release of the client!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area: Specification Related to the API spec used to generate client code Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants