# Update in multi level

**URL:** <https://discuss.elastic.co/t/update-in-multi-level/7613>\
**Category:** Elasticsearch\
**Created:** [May 9, 2012, 1:14pm UTC](https://discuss.elastic.co/t/update-in-multi-level/7613 "2012-05-09T13:14:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [May 9, 2012, 1:14pm UTC](https://discuss.elastic.co/t/update-in-multi-level/7613/1 "2012-05-09T13:14:13Z")

</div>

Hi,

I've some file which looks like that :

id  
description

primary\_tag  
tag : value  
tag : value  
primary\_tag  
tag : value  
...

The two first line has already here but the other can be more  
important or unexists so i've a script which puts in a array all  
primary\_tag, in other the tag and one other array contain values.

So to index them i've done :

$result = $es-\>index(  
index =\> $index,  
type =\> $type,  
id =\> $i,  
data =\> {  
id =\> $id,  
DESC =\> $desc  
},  
);

my $k = 0;  
foreach my $features\_object (@features){

```
					my $bornes = $bornes_inf[$k]."..".$bornes_sup[$k];

					my $primary_tag = $features_object->primary_tag();
					$primary_tag = uc($primary_tag);

					for($features_object->get_all_tags()){

						my $tag = $_;

						for my $valeur ($features_object->get_tag_values($tag)){

							$result = $es->update(
								index	=>	$index,
								type	=>	$type,
								id =>	$i,

								script	=> "ctx._source[\"$primary_tag\_$bornes/$tag\"]=

```

"$valeur"",  
params =\> {"$primary\_tag\_$bornes/$tag" =\> 'ok'}  
);  
}  
}  
$k++;  
}

The problem is that script index data with field : prymary\_tag/bornes/  
tag : value because some tag can be similar so i use "borne" to  
differency them.

I search a script for updating like that :

primary\_tag { tag1 : "value", tag2 : "value" }

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [May 9, 2012, 2:03pm UTC](https://discuss.elastic.co/t/update-in-multi-level/7613/2 "2012-05-09T14:03:07Z")

</div>

I've try this script but it does'nt works :

"if(ctx.\_source.$primary\_tag\_$bornes["$tag"]==null) { ctx.\_source.  
$primary\_tag\_$bornes["$tag"] = "$value"} else {ctx.\_source.  
$primary\_tag\_$bornes["$tag"] += " $value"}"

I want this script do :

if the tag in the primary tag we works is undef, add $primary\_tag\_  
$bornes{ $tag : "$value" }, else add just the value to the fields.

The problem is not var's name, i change it in my code and the problem  
still here.

I have no idea

On 9 mai, 15:14, Jérome [pivertjer...@gmail.com](mailto:pivertjer...@gmail.com) wrote:

> Hi,
> 
> I've some file which looks like that :
> 
> id  
> description
> 
> primary\_tag  
> tag : value  
> tag : value  
> primary\_tag  
> tag : value  
> ...
> 
> The two first line has already here but the other can be more  
> important or unexists so i've a script which puts in a array all  
> primary\_tag, in other the tag and one other array contain values.
> 
> So to index them i've done :
> 
> $result = $es-\>index(  
> index =\> $index,  
> type =\> $type,  
> id =\> $i,  
> data =\> {  
> id =\> $id,  
> DESC =\> $desc  
> },  
> );
> 
> my $k = 0;  
> foreach my $features\_object (@features){
> 
> ```
> my $bornes = $bornes_inf[$k]."..".$bornes_sup[$k];
> 
> my $primary_tag = $features_object->primary_tag();
> $primary_tag = uc($primary_tag);
> 
> for($features_object->get_all_tags()){
> 
> my $tag = $_;
> 
> for my $valeur ($features_object->get_tag_values($tag)){
> 
> $result = $es->update(
> index => $index,
> type => $type,
> id => $i,
> 
> script => "ctx._source[\"$primary_tag\_$bornes/$tag\"]=
> 
> ```
> 
> "$valeur"",  
> params =\> {"$primary\_tag\_$bornes/$tag" =\> 'ok'}  
> );  
> }  
> }  
> $k++;  
> }
> 
> The problem is that script index data with field : prymary\_tag/bornes/  
> tag : value because some tag can be similar so i use "borne" to  
> differency them.
> 
> I search a script for updating like that :
> 
> primary\_tag { tag1 : "value", tag2 : "value" }

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 10, 2012, 9:23pm UTC](https://discuss.elastic.co/t/update-in-multi-level/7613/3 "2012-05-10T21:23:09Z")

</div>

Hard to tell what you are trying to do, is there a chance for a simple curl  
recreation? (see [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).

On Wed, May 9, 2012 at 5:03 PM, Jérome [pivertjerome@gmail.com](mailto:pivertjerome@gmail.com) wrote:

> I've try this script but it does'nt works :
> 
> "if(ctx.\_source.$primary\_tag\_$bornes["$tag"]==null) { ctx.\_source.  
> $primary\_tag\_$bornes["$tag"] = "$value"} else {ctx.\_source.  
> $primary\_tag\_$bornes["$tag"] += " $value"}"
> 
> I want this script do :
> 
> if the tag in the primary tag we works is undef, add $primary\_tag\_  
> $bornes{ $tag : "$value" }, else add just the value to the fields.
> 
> The problem is not var's name, i change it in my code and the problem  
> still here.
> 
> I have no idea
> 
> On 9 mai, 15:14, Jérome [pivertjer...@gmail.com](mailto:pivertjer...@gmail.com) wrote:
> 
> > Hi,
> > 
> > I've some file which looks like that :
> > 
> > id  
> > description
> > 
> > primary\_tag  
> > tag : value  
> > tag : value  
> > primary\_tag  
> > tag : value  
> > ...
> > 
> > The two first line has already here but the other can be more  
> > important or unexists so i've a script which puts in a array all  
> > primary\_tag, in other the tag and one other array contain values.
> > 
> > So to index them i've done :
> > 
> > $result = $es-\>index(  
> > index =\> $index,  
> > type =\> $type,  
> > id =\> $i,  
> > data =\> {
> 
> ```
> id => $id,
> 
> ```
> 
> > 
> 
> ```
> DESC => $desc
> 
> ```
> 
> > 
> 
> },
> 
> > ```
> > );
> > 
> > ```
> > 
> > my $k = 0;  
> > foreach my $features\_object  
> > (@features){
> > 
> > ```
> > my $bornes =
> > 
> > ```
> 
> $bornes\_inf[$k]."..".$bornes\_sup[$k];
> 
> > ```
> > my $primary_tag =
> > 
> > ```
> 
> $features\_object-\>primary\_tag();
> 
> > ```
> > $primary_tag =
> > 
> > ```
> 
> uc($primary\_tag);
> 
> > 
> 
> for($features\_object-\>get\_all\_tags()){
> 
> > ```
> > my $tag = $_;
> > 
> > for my $valeur
> > 
> > ```
> 
> ($features\_object-\>get\_tag\_values($tag)){
> 
> > ```
> > $result
> > 
> > ```
> 
> = $es-\>update(
> 
> > 
> 
> index =\> $index,
> 
> > 
> 
> type =\> $type,
> 
> > 
> 
> id =\> $i,
> 
> > 
> 
> script =\> "ctx.\_source["$primary\_tag\_$bornes/$tag"]=
> 
> > "$valeur"",
> 
> params =\> {"$primary\_tag\_$bornes/$tag" =\> 'ok'}
> 
> > ```
> > );
> > }
> > }
> > $k++;
> > }
> > 
> > ```
> > 
> > The problem is that script index data with field : prymary\_tag/bornes/  
> > tag : value because some tag can be similar so i use "borne" to  
> > differency them.
> > 
> > I search a script for updating like that :
> > 
> > primary\_tag { tag1 : "value", tag2 : "value" }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:29am UTC](https://discuss.elastic.co/t/update-in-multi-level/7613/4 "2017-07-06T03:29:21Z")

</div>

Closed on July 6, 2017, 3:29am UTC


