How to set script parameter type


(George-3) #1

Hi all,

I hope someone would be able to shed light into the problem I am
experiencing.

I am having trouble with trying to set the "type" of "params" in a
script, so that they match the type in the mapping.

For the following type mapping:

{
"book": {
"properties": {
"FileName": { "filter": [ "lowercase" ], "type": "string" },
"Members": { "type": "long", "null_value": 0, "store" : "yes" },
"Blacklist": { "type": "long", "null_value": 0, "store" :
"yes" }
}
}
}

I use the following script in a query:

"script": {
"script": "(((doc['Members'] & fieldValue)!=0) AND
((doc['Blacklist'] & fieldValue)==0))",
"params": { "fieldValue": -1 }
}

I kept on getting type mismatch error.

RuntimeException[could not perform numeric operation on non-numeric
types: left-
type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-
type=java.lang.Integer [vals
(org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,
-1) operation=BIT_AND (opcode:6) ]]


(George-3) #2

Never mind, I had solved the issue.

for those who might had the same issue,
the mapping should just state:

"Members": { "type": "integer"}

On Jul 7, 9:08 am, George gershwinlu...@gmail.com wrote:

Hi all,

I hope someone would be able to shed light into the problem I am
experiencing.

I am having trouble with trying to set the "type" of "params" in a
script, so that they match the type in the mapping.

For the following type mapping:

{
"book": {
"properties": {
"FileName": { "filter": [ "lowercase" ], "type": "string" },
"Members": { "type": "long", "null_value": 0, "store" : "yes" },
"Blacklist": { "type": "long", "null_value": 0, "store" :
"yes" }
}
}

}

I use the following script in a query:

"script": {
"script": "(((doc['Members'] & fieldValue)!=0) AND
((doc['Blacklist'] & fieldValue)==0))",
"params": { "fieldValue": -1 }

}

I kept on getting type mismatch error.

RuntimeException[could not perform numeric operation on non-numeric
types: left-
type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-
type=java.lang.Integer [vals
(org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,
-1) operation=BIT_AND (opcode:6) ]]


(Shay Banon) #3

I am not sure that this is your problem, I think the problem is: doc['field_name'].value (note calling value at the end).

On Thursday, July 7, 2011 at 3:10 AM, George wrote:

Never mind, I had solved the issue.

for those who might had the same issue,
the mapping should just state:

"Members": { "type": "integer"}

On Jul 7, 9:08 am, George <gershwinlu...@gmail.com (http://gmail.com)> wrote:

Hi all,

I hope someone would be able to shed light into the problem I am
experiencing.

I am having trouble with trying to set the "type" of "params" in a
script, so that they match the type in the mapping.

For the following type mapping:

{
"book": {
"properties": {
"FileName": { "filter": [ "lowercase" ], "type": "string" },
"Members": { "type": "long", "null_value": 0, "store" : "yes" },
"Blacklist": { "type": "long", "null_value": 0, "store" :
"yes" }
}
}

}

I use the following script in a query:

"script": {
"script": "(((doc['Members'] & fieldValue)!=0) AND
((doc['Blacklist'] & fieldValue)==0))",
"params": { "fieldValue": -1 }

}

I kept on getting type mismatch error.

RuntimeException[could not perform numeric operation on non-numeric
types: left-
type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-
type=java.lang.Integer [vals
(org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,
-1) operation=BIT_AND (opcode:6) ]]


(system) #4