Hi !
First, thanks for explain Igor.
I've try the ctx._source but doesn't works.
I show you the entire script (little script just to test update
function)
Script
#!/usr/bin/perl
use strict;
use warnings;
use ElasticSearch;
my $es = ElasticSearch->new(
transport => 'http',
servers => 'localhost:9200',
trace_calls => 1,
timeout => 30,
max_requests => 10_000,
no_refresh => 0
);
my ($result, $tag);
my $i;
for($i=1; $i < 5; $i++){
if($i == 1){
$result = $es->index(
index => "toto",
type => "tata",
id => 1,
data => {
name => "big",
surname => "muzzy"
},
);
}
else{
print "tag : ";
chomp($tag = <STDIN>);
$result = $es->update(
index => "toto",
type => "tata",
id => 1,
script => {"ctx._source[\"$tag\"].value=["foo"]"},
params
=> {$tag => 'ok'}
);
}
}
Error message
Odd number of elements in anonymous hash at ./testupdate.pl line 42,
line 1.
[Mon Apr 23 14:49:55 2012] Protocol: http, Server:
193.51.160.124:9200
curl -XPOST 'http://127.0.0.1:9200/toto/tata/1/_update?pretty=1' -d '
{
"params" : {
"plop" : "ok"
},
"script" : {
"ctx._source["plop"].value=["tags"]" : null
}
}
'
[Mon Apr 23 14:49:55 2012] Response:
{
"status" : 400,
"error" : "ElasticSearchIllegalArgumentException[failed to exe
> cute script]; nested: CompileException[[Error: unterminated
> collection element]\n[Near : {... {ctx._source["plop"].val
> ue=["tags"]=null} ....}]\n
> ^\n[Line: 1, Column: 36]]; "
}
[ERROR] ** ElasticSearch::Error::Request at /Library/Perl/5.10.0/
ElasticSearch/Transport/HTTP.pm line 60 :
ElasticSearchIllegalArgumentException[failed to execute script];
nested: CompileException[[Error: unterminated collection element]
[Near : {... {ctx._source["plop"].value=["tags"]=null} ....}]
^
[Line: 1, Column: 36]];
With vars:{
'request' => {
'post_process' => undef,
'qs' => {},
'cmd' => '/toto/tata/1/_update',
'as_json' => undef,
'data' => {
'params' => {
'plop' => 'ok'
},
'script' => {
'ctx._source["plop"].value=["tags"]' => undef
}
},
'method' => 'POST'
},
'status_code' => 400,
'server' => '193.51.160.124:9200',
'status_msg' => 'Bad Request'
}
I don't understand the problem...
Jerome