Skip to content

put_script() defaults to mustache #132

New issue

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

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

Already on GitHub? Sign in to your account

Closed
A80qWEHg opened this issue Nov 30, 2017 · 3 comments
Closed

put_script() defaults to mustache #132

A80qWEHg opened this issue Nov 30, 2017 · 3 comments

Comments

@A80qWEHg
Copy link

A80qWEHg commented Nov 30, 2017

Since 6.0 I have issues with stored scripts. The lang is set to "mustache" and therefore ES can't interpret them correctly. Also the resulting stored script is not always the same ?!

#!/usr/bin/perl -w
use strict; 
use Search::Elasticsearch 6.0;

my $e = Search::Elasticsearch->new;

# according to the documentation the lang defaults to painless
# --> https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html

$e->put_script(
    id   => 'test',
    body => { 
        lang => 'painless',
        source => q(return), 
    },
);

print `curl -s localhost:9200/_scripts/test?pretty`;

By running this script multiple times I get two different outputs in random order:

{
  "_id" : "test",
  "found" : true,
  "script" : {
    "lang" : "mustache",
    "source" : "{\"source\":\"return\"}"
  }
}
{
  "_id" : "test",
  "found" : true,
  "script" : {
    "lang" : "mustache",
    "source" : "{\"lang\":\"painless\"}"
  }
}

Strange stuff!

This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux
Version: 6.0.0, Build: 8f0685b/2017-11-10T18:41:22.859Z, JVM: 1.8.0_152

@clintongormley
Copy link
Contributor

There are two issues here. First, you're using the wrong syntax, use this instead:

$e->put_script(
    id   => 'test',
    body => { 
        script => {
            lang => 'painless',
            source => q(return)
        }
    }
);

And second, a bug in Elasticsearch that it is accepting this malformed request. I have opened elastic/elasticsearch#27612 to get that fixed.

@A80qWEHg
Copy link
Author

A80qWEHg commented Dec 1, 2017

Thank you very much for your time and advice. Maybe you can update the example in https://metacpan.org/pod/Search::Elasticsearch::Client::6_0::Direct#put_script() as well?
That would be awesome.

clintongormley added a commit that referenced this issue Dec 1, 2017
@clintongormley
Copy link
Contributor

Ah thanks for pointing that out. I've pushed a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants