Date comparisons in update api script fields

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.

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 rwickell@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.

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.

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.

On a related note to this , I wanted to be able to call the update api
and a realtime get on the same object in one
call. I have used the multiget for getting multiple objects as well as
a multisearch to get several search results at once
but wondering if there is a way to pass both an update call and a get
call in one request?
The object has no analyzable fields in the mapping on purpose since I
will never search the contents, only be grabbing the source
after using the update api call. Any way to put these two calls
together in one request? update call (listed in thread above), get
call for same object in the update call
Will this pose any issue for the server having to search through
transaction log a lot for objects just updated? will the updates
always show ?, assuming they will since
the realtime get should show all prior updates to their source,
correct?

-Rusty

Thanks again, really enjoying the software. Have a long history with
mysql but this project I am currently doing uses alot of text search
and this product really made sense for it.

On Mar 28, 8:53 am, rusty rwick...@gmail.com wrote:

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.

Just thinking, how difficult would it be to add an option to the
update api call to return the source after the update in the return
json? maybe this already exists, but haven't seen it.

Thanks,
Rusty

On Mar 28, 9:18 am, rusty rwick...@gmail.com wrote:

On a related note to this , I wanted to be able to call the update api
and a realtime get on the same object in one
call. I have used the multiget for getting multiple objects as well as
a multisearch to get several search results at once
but wondering if there is a way to pass both an update call and a get
call in one request?
The object has no analyzable fields in the mapping on purpose since I
will never search the contents, only be grabbing the source
after using the update api call. Any way to put these two calls
together in one request? update call (listed in thread above), get
call for same object in the update call
Will this pose any issue for the server having to search through
transaction log a lot for objects just updated? will the updates
always show ?, assuming they will since
the realtime get should show all prior updates to their source,
correct?

-Rusty

Thanks again, really enjoying the software. Have a long history with
mysql but this project I am currently doing uses alot of text search
and this product really made sense for it.

On Mar 28, 8:53 am, rusty rwick...@gmail.com wrote:

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.

Hey Rusty.

It would be useful, I have created an issue for it
add return script option to the update API · Issue #1822 · elastic/elasticsearch · GitHub.

Expect it to be implemented soon.

On Wednesday, March 28, 2012 6:22:02 PM UTC+2, rusty wrote:

Just thinking, how difficult would it be to add an option to the
update api call to return the source after the update in the return
json? maybe this already exists, but haven't seen it.

Thanks,
Rusty

On Mar 28, 9:18 am, rusty rwick...@gmail.com wrote:

On a related note to this , I wanted to be able to call the update api
and a realtime get on the same object in one
call. I have used the multiget for getting multiple objects as well as
a multisearch to get several search results at once
but wondering if there is a way to pass both an update call and a get
call in one request?
The object has no analyzable fields in the mapping on purpose since I
will never search the contents, only be grabbing the source
after using the update api call. Any way to put these two calls
together in one request? update call (listed in thread above), get
call for same object in the update call
Will this pose any issue for the server having to search through
transaction log a lot for objects just updated? will the updates
always show ?, assuming they will since
the realtime get should show all prior updates to their source,
correct?

-Rusty

Thanks again, really enjoying the software. Have a long history with
mysql but this project I am currently doing uses alot of text search
and this product really made sense for it.

On Mar 28, 8:53 am, rusty rwick...@gmail.com wrote:

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.

Great! Thank you :slight_smile:

On Mar 29, 5:26 am, Benjamin Devèze benjamin.dev...@gmail.com wrote:

Hey Rusty.

It would be useful, I have created an issue for ithttps://github.com/elasticsearch/elasticsearch/issues/1822.

Expect it to be implemented soon.

On Wednesday, March 28, 2012 6:22:02 PM UTC+2, rusty wrote:

Just thinking, how difficult would it be to add an option to the
update api call to return the source after the update in the return
json? maybe this already exists, but haven't seen it.

Thanks,
Rusty

On Mar 28, 9:18 am, rusty rwick...@gmail.com wrote:

On a related note to this , I wanted to be able to call the update api
and a realtime get on the same object in one
call. I have used the multiget for getting multiple objects as well as
a multisearch to get several search results at once
but wondering if there is a way to pass both an update call and a get
call in one request?
The object has no analyzable fields in the mapping on purpose since I
will never search the contents, only be grabbing the source
after using the update api call. Any way to put these two calls
together in one request? update call (listed in thread above), get
call for same object in the update call
Will this pose any issue for the server having to search through
transaction log a lot for objects just updated? will the updates
always show ?, assuming they will since
the realtime get should show all prior updates to their source,
correct?

-Rusty

Thanks again, really enjoying the software. Have a long history with
mysql but this project I am currently doing uses alot of text search
and this product really made sense for it.

On Mar 28, 8:53 am, rusty rwick...@gmail.com wrote:

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.

Ok a patch has been pushed in master and the feature will be available in
next released version.

Have a look here for more details

On Thursday, March 29, 2012 4:39:40 PM UTC+2, rusty wrote:

Great! Thank you :slight_smile:

On Mar 29, 5:26 am, Benjamin Devèze benjamin.dev...@gmail.com wrote:

Hey Rusty.

It would be useful, I have created an issue for ithttps://
add return script option to the update API · Issue #1822 · elastic/elasticsearch · GitHub.

Expect it to be implemented soon.

On Wednesday, March 28, 2012 6:22:02 PM UTC+2, rusty wrote:

Just thinking, how difficult would it be to add an option to the
update api call to return the source after the update in the return
json? maybe this already exists, but haven't seen it.

Thanks,
Rusty

On Mar 28, 9:18 am, rusty rwick...@gmail.com wrote:

On a related note to this , I wanted to be able to call the update
api
and a realtime get on the same object in one
call. I have used the multiget for getting multiple objects as well
as
a multisearch to get several search results at once
but wondering if there is a way to pass both an update call and a
get
call in one request?
The object has no analyzable fields in the mapping on purpose since
I
will never search the contents, only be grabbing the source
after using the update api call. Any way to put these two calls
together in one request? update call (listed in thread above), get
call for same object in the update call
Will this pose any issue for the server having to search through
transaction log a lot for objects just updated? will the updates
always show ?, assuming they will since
the realtime get should show all prior updates to their source,
correct?

-Rusty

Thanks again, really enjoying the software. Have a long history with
mysql but this project I am currently doing uses alot of text search
and this product really made sense for it.

On Mar 28, 8:53 am, rusty rwick...@gmail.com wrote:

Nevermind, I fixed it. I checked the syntax and I can just use the
normal if{} else {} syntax to fix this.
Works fine now, thanks for the help.

-Rusty

On Mar 28, 8:10 am, rusty rwick...@gmail.com wrote:

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.