Scripts stored via TransportClient lose fields in source


I just discovered a strange behavior of the TransportClient in ES 5.6.11. Maybe a bug, maybe just wrong usage. When I store a script via the TransportClient then all fields but the first field get lost in the source. When I store the same script source via REST it works fine.

I prepared a toy example showing it:

It starts an ES node in a docker container, stores scripts using transport and REST client and then prints the different results.

Is this a bug or intended behavior?

I know, switching to the REST client would solve the problem. But this is not a trivial task in our production system. Any ideas?

This sounds like a possible bug in how stored scripts are parsed, but that code has undergone a lot of refactoring since 5.6. In fact, the way you are passing your template (at the root of the request) is deprecated, and just recently removed in master for 7.0. I recommend moving your template inside a script element, which is the new way of doing things (so all scripts are the same, whether they are templates or not):

"script": {
    "lang": mustache",
    "source": { ... your template query }

Hi Ryan,

thanks for your suggestion. Actually, it worked wrapping the query inside a script field directly:

    "script": {
        "query": { "match_all": {} },
        "size": 6

The Java code looks like this:

scriptSource = "{\"query\": {\"match_all\": {}},\"size\": 6}";
            new BytesArray("{\"script\":" + scriptSource + "}"),

Not beautiful, but it works.. :slight_smile: ..the resulting script is stored as:

  "_id": "TEST",
  "found": true,
  "script": {
    "lang": "mustache",
    "source": """{"query":{"match_all":{}},"size":6}"""

Thanks for your help!

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