Script for adding new object


(Jérome) #1

Hi everyone,

I've a little question about scripting i've try to make a script who
adds a new object if it doesn't exist but doesn't works.

{
object {
tag : value,
tag2 : value
},
tag : value,

object2 { tag : value }

}

I want update this things. I want create a new object if doesn't exist
and add the new tag/value into but if object exist i just want add the
tag : value.

For example i've : $myObject = "foo"; $tag = "bar"; $value = "val";

I want create the sructure foo { bar : val } and add it into my
index.

I've try this script but doesn't works :

if(ctx._source.$myObject){
if(ctx._source.$myObject["$tag"] == null){
ctx._source.$myObject["$tag"] = "$value"
}
else {
ctx._source.$myObject["$tag"] += " $value"
}
}
else {
ctx._source.$myObject["$tag"] = "$value"
}

So i don't understand why it doesn't work. Someone ?


(Jérome) #2

Ah, wrong backslash into this code, but it's not the problem.

On 14 mai, 11:30, Jérome pivertjer...@gmail.com wrote:

Hi everyone,

I've a little question about scripting i've try to make a script who
adds a new object if it doesn't exist but doesn't works.

{
object {
tag : value,
tag2 : value
},
tag : value,

object2 { tag : value }

}

I want update this things. I want create a new object if doesn't exist
and add the new tag/value into but if object exist i just want add the
tag : value.

For example i've : $myObject = "foo"; $tag = "bar"; $value = "val";

I want create the sructure foo { bar : val } and add it into my
index.

I've try this script but doesn't works :

if(ctx._source.$myObject){
if(ctx._source.$myObject["$tag"] == null){
ctx._source.$myObject["$tag"] = "$value"
}
else {
ctx._source.$myObject["$tag"] += " $value"
}}

else {
ctx._source.$myObject["$tag"] = "$value"

}

So i don't understand why it doesn't work. Someone ?


(Jérome) #3

I want to know if it's possible first ^^


(Shay Banon) #4

Yes, it should be possible. If you have problems with the default mvel
lang, install the javascript plugin and use it instead.

On Mon, May 14, 2012 at 5:18 PM, Jérome pivertjerome@gmail.com wrote:

I want to know if it's possible first ^^


(system) #5