Script Filters

Hi all,
This is the second time I post this question. It is VERY URGENT. Could some one help me with it?
I have a Script Filters defined in the couchdb river.
In this script I need to refer to a field of the documents which has special
characters on it, e.g. '-'
So the field would be, for example: 'number-of-houses'

How can I refer to this field from the Script Filter ??

In a normal javascript in a view I would use doc['number-of-houses'], but in
the Script Filters I don't know...
I tried:

ctx.doc['number-of-houses']
ctx.doc.'number-of-houses'
ctx[doc]['number-of-houses']
...

...but none of these options works.
Do you know how should I refer to this field?

Many thanks in advance!!

Do you refer to a script defined in the river when you create it? Using
ctx['doc']['number-of-houses'] shoudl work. How do you create teh river?
Maybe you do it with curl and use ' to denote the body of the message?

On Sun, Mar 25, 2012 at 12:08 AM, posejavier posejavier@hotmail.com wrote:

Hi all,
This is the second time I post this question. It is VERY URGENT. Could some
one help me with it?
I have a Script Filters defined in the couchdb river.
In this script I need to refer to a field of the documents which has
special
characters on it, e.g. '-'
So the field would be, for example: 'number-of-houses'

How can I refer to this field from the Script Filter ??

In a normal javascript in a view I would use doc['number-of-houses'], but
in
the Script Filters I don't know...
I tried:

ctx.doc['number-of-houses']
ctx.doc.'number-of-houses'
ctx[doc]['number-of-houses']
...

...but none of these options works.
Do you know how should I refer to this field?

Many thanks in advance!!

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Script-Filters-tp3854642p3854642.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Hi,
many thanks for the reply (!!!)
You are right, I am using curl to create the river and and use ' to denote the body of the message. Should I do it in another way?

I tried the ctx['doc']['number-of-houses'] in my curl code but still ES gives the same error:

The curl that I used is:

curl -XPUT 'localhost:9200/_river/database1/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "database1",
"filter" : null,
"script" : "if (ctx['doc']['number-of-houses']) ctx['doc']['number-of-houses'] = null"
},
"index" : {
"index" : "database1",
"type" : "database1",
"bulk_size" : "100",
"bulk_timeout" : "10ms"
}
}'

...but still ES gives the same error:

[2012-03-26 00:25:11,982][WARN ][river.couchdb ] [Rusty Collins] [cou
chdb][database1] failed to script process {id=74a18d549947f264d0d8b553cf005d81,
doc={_rev=1-967a00dff5e02add41819138abb3284d, _id=74a18d549947f264d0d8b553cf005d
81}, seq=46, changes=[{rev=1-967a00dff5e02add41819138abb3284d}]}, ignoring
org.mozilla.javascript.EcmaError: ReferenceError: "doc" is not defined. (Script1
.js#1)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3785)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3763)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java
:3848)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1781)
at org.mozilla.javascript.gen.Script1_js_1._c_script_0(Script1.js:1)
at org.mozilla.javascript.gen.Script1_js_1.call(Script1.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:4
26)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:317
8)
at org.mozilla.javascript.gen.Script1_js_1.call(Script1.js)
at org.mozilla.javascript.gen.Script1_js_1.exec(Script1.js)
at org.elasticsearch.script.javascript.JavaScriptScriptEngineService$Jav
aScriptExecutableScript.run(JavaScriptScriptEngineService.java:186)
at org.elasticsearch.river.couchdb.CouchdbRiver.processLine(CouchdbRiver
.java:236)
at org.elasticsearch.river.couchdb.CouchdbRiver.access$500(CouchdbRiver.
java:64)
at org.elasticsearch.river.couchdb.CouchdbRiver$Indexer.run(CouchdbRiver
.java:329)
at java.lang.Thread.run(Unknown Source)
[2012-03-26 00:25:12,043][INFO ][cluster.metadata ] [Rusty Collins] [_ri
ver] update_mapping [database1] (dynamic)
[2012-03-26 00:27:07,258][INFO ][cluster.metadata ] [Rusty Collins] [dat
abase1] deleting index
[2012-03-26 00:27:14,296][INFO ][cluster.metadata ] [Rusty Collins] [_ri
ver] deleting index
[2012-03-26 00:27:14,298][INFO ][river.couchdb ] [Rusty Collins] [cou
chdb][database1] closing couchdb stream river

check the -d ', it means that the string starts, and then you use ' in the
body...

On Mon, Mar 26, 2012 at 12:32 AM, posejavier posejavier@hotmail.com wrote:

Hi,
many thanks for the reply (!!!)
You are right, I am using curl to create the river and and use ' to denote
the body of the message. Should I do it in another way?

I tried the ctx['doc']['number-of-houses'] in my curl code but still ES
gives the same error:

The curl that I used is:

curl -XPUT 'localhost:9200/_river/database1/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "database1",
"filter" : null,
"script" : "if (ctx['doc']['number-of-houses'])
ctx['doc']['number-of-houses'] = null"
},
"index" : {
"index" : "database1",
"type" : "database1",
"bulk_size" : "100",
"bulk_timeout" : "10ms"
}
}'

...but still ES gives the same error:

[2012-03-26 00:25:11,982][WARN ][river.couchdb ] [Rusty Collins]
[cou
chdb][database1] failed to script process
{id=74a18d549947f264d0d8b553cf005d81,
doc={_rev=1-967a00dff5e02add41819138abb3284d,
_id=74a18d549947f264d0d8b553cf005d
81}, seq=46, changes=[{rev=1-967a00dff5e02add41819138abb3284d}]}, ignoring
org.mozilla.javascript.EcmaError: ReferenceError: "doc" is not defined.
(Script1
.js#1)
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3785)
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a:3763)
at
org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java
:3848)
at
org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1781)
at org.mozilla.javascript.gen.Script1_js_1._c_script_0(Script1.js:1)
at org.mozilla.javascript.gen.Script1_js_1.call(Script1.js)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:4
26)
at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:317
8)
at org.mozilla.javascript.gen.Script1_js_1.call(Script1.js)
at org.mozilla.javascript.gen.Script1_js_1.exec(Script1.js)
at
org.elasticsearch.script.javascript.JavaScriptScriptEngineService$Jav
aScriptExecutableScript.run(JavaScriptScriptEngineService.java:186)
at
org.elasticsearch.river.couchdb.CouchdbRiver.processLine(CouchdbRiver
.java:236)
at
org.elasticsearch.river.couchdb.CouchdbRiver.access$500(CouchdbRiver.
java:64)
at
org.elasticsearch.river.couchdb.CouchdbRiver$Indexer.run(CouchdbRiver
.java:329)
at java.lang.Thread.run(Unknown Source)
[2012-03-26 00:25:12,043][INFO ][cluster.metadata ] [Rusty Collins]
[_ri
ver] update_mapping [database1] (dynamic)
[2012-03-26 00:27:07,258][INFO ][cluster.metadata ] [Rusty Collins]
[dat
abase1] deleting index
[2012-03-26 00:27:14,296][INFO ][cluster.metadata ] [Rusty Collins]
[_ri
ver] deleting index
[2012-03-26 00:27:14,298][INFO ][river.couchdb ] [Rusty Collins]
[cou
chdb][database1] closing couchdb stream river

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Script-Filters-tp3854642p3856836.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Many thanks !!!
It worked perfect :slight_smile: