System.currentTimeInMillis didn't work for me. I was able to just use
a string as a parameter and pass in the current time. It works so far
except for one hitch
maybe you can help me with:
In the case where the first statement is true (ct._source.5sects >
current) See below for current object as well.
In the case of it being true is doesn't execute the rest of the
commands seperaated by ;, but if it is false it will
execute the all after the initial conditional. Is there a way to
specify that the following statement after the conditional are not
attached to the conditional statement?
curl -XPOST 'http://localhost:9200/mystats1/stats1/1/_update' -d '{
"script" : "ctx._source.5sects > current ? ctx._source.5seccnt +=
count : ctx._source.5sects=current;ctx._source.1mincnt += count;
ctx._source.10mincnt
+= count;ctx._source.1hrcnt += count;ctx._source.1daycnt += count"
,
"params" : {
"count" : 1,
"current" : "2012-03-28T00:00:00"
}
}'
{"5sects":"2012-03-26T16:00:00","5seccnt":
8,"1mints":"2012-03-26T16:00:00","1mincnt":
12,"10mints":"2012-03-26T16:00:00","10mincnt":
13,"1hrts":"2012-03-26T16:00:00","1hrcnt":
19,"1dayts":"2012-03-26T00:00:00","1daycnt":
25,"blacklisted":"false","blacklistexpire":"2032-01-01T00:00:00"}
Thanks for the input,
Rusty
On Mar 27, 10:43 am, Shay Banon kim...@gmail.com wrote:
First, you can't pass several strings to the script parameter. You can (in
mvel, which is the default scripting used) separate each by ";" within a
single script. Also, try and replace now with System.currentTimeInMillis,
see if it helps.
On Tue, Mar 27, 2012 at 6:43 AM, rusty rwick...@gmail.com wrote:
I have a question about the update api, I am able to update fields
that are integers already, but wanted to be able to do a date
comparison like so: "script" : "now - 5s <= ctx._source.5sects ?
ctx._source.5seccnt += count : ctx._source.5sects=now" , es doen't
accept this, but wondering if it will accept any other type of date
arithmetic in the script?
ctx._source.5sects is a date field and already mapped before inserting
any data
Is it possible to do this kind of comparison? do I just have the
syntax wrong?
Here is the error on 0.19 rc3
{"error":"ElasticSearchIllegalArgumentException[failed to execute
script]; nested: PropertyAccessException[[Error: unresolvable property
or identifier: now]\n[Near : {... now - 5s <= ctx._source.5sects ....}]
\n ^\n[Line: 1, Column: 1]]; ","status":400}
Here is the curl call:
curl -XPOST 'http://localhost:9200/mystats1/stats1/1/_update'-d '{
"script" : [ "now - 5sec < = ctx._source.5sects ? ctx._source.
5seccnt += count : ctx._source.5sects=now",
"ctx._source.1mincnt += count",
"ctx._source.10mincnt += count",
"ctx._source.1hrcnt += count",
"ctx._source.1daycnt += count"
],
"params" : {
"count" : 1
}
}'
works fine except for when I try to add the date arithmetic part of
it.
Any help appeciated,
Thanks,
Rusty
ps. great product, just getting started but love it already.