# Script template to manipulate records using parameters

**URL:** <https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429>\
**Category:** Elasticsearch\
**Created:** [June 6, 2017, 1:48pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429 "2017-06-06T13:48:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rschirin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rschirin/32/45283_2.png) [@rschirin](https://discuss.elastic.co/u/rschirin)\
**Post date:** [June 6, 2017, 1:48pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/1 "2017-06-06T13:48:48Z")

</div>

Hi,  
actually, into different indexes, I have duplicated records which have the same field's values but, obviously, different `_id` value.  
so, trying to remove these duplicated records this is what I would like to do:

1. query a specific index
2. compare each found record with the others located inside index above
3. if `myfield` record's value1 is equal to `myfield` record's value2 drop record1

essentially, writing this procedure in a generic scripting language it will looks like:

```
foreach element into index.2017.06.6 {
     do {
        if element.myvalue equal element[+1].myvalue{
           delete element    
         }
      }
}

```

can someone help me? I don't want the code to do that, I would like to have some guidelines to understand the mechanism behind the execution of scripts and how can I pass parameters inside my search.

thanks

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 7, 2017, 3:38am UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/2 "2017-06-07T03:38:44Z")

</div>

You won't be able to do this within a search script, since the script can only decide if a document matches the search, not try to remove a document at the same time. I think you will need to do this from your client. I don't think you will need an elasticsearch script though. It should just be a normal query, look at the results with the pseudocode you already have above, and if you find the condition you are looking for, issue a delete request for that document.

---

<div class="post-metadata">

**Author:** ![rschirin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rschirin/32/45283_2.png) [@rschirin](https://discuss.elastic.co/u/rschirin)\
**Post date:** [June 7, 2017, 6:38pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/3 "2017-06-07T18:38:29Z")

</div>

thank you for the answer. one doubt? what do you mean with "...you will need to do this from your client" ?  
which client?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 7, 2017, 8:10pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/4 "2017-06-07T20:10:21Z")

</div>

I mean from your application, which is using some client (whether eg an elasticsearch client or using http directly).

---

<div class="post-metadata">

**Author:** ![rschirin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rschirin/32/45283_2.png) [@rschirin](https://discuss.elastic.co/u/rschirin)\
**Post date:** [June 8, 2017, 2:35pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/5 "2017-06-08T14:35:52Z")

</div>

I feel myself really stupid.  
actually this is my structure

1. one script is extracting data to fill a file called MyFile
2. filebeat reads MyFile
3. filebeat sends read records to Logstash
4. Logstash normalize them and sends them to Elastic

---

<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, 2:35pm UTC](https://discuss.elastic.co/t/script-template-to-manipulate-records-using-parameters/88429/6 "2017-07-06T14:35:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
