# The difference between using script in pipeline and using normal script to update document

**URL:** <https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951>\
**Category:** Elasticsearch\
**Created:** [July 6, 2020, 3:44am UTC](https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951 "2020-07-06T03:44:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FFFro](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@FFFro](https://discuss.elastic.co/u/FFFro)\
**Post date:** [July 6, 2020, 3:44am UTC](https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951/1 "2020-07-06T03:44:08Z")

</div>

Now I'd like to update documents with parent-child relationships. When I use script to update, prompt me "field"[\_ routing] is a metadata field and cannot be added inside a document. Use the index API request parameters.".

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/e/ce344b0eb56f9e1c9d8946f34ef811a7f02e7543.jpeg) .  
But when I use a pipeline casually，like

```auto
PUT _ingest/pipeline/test
{
 "processors": [
   {
     "set": {
       "field": "city",
       "value": "beiji"
     }
   }
 ]
}
POST my_index/_update_by_query?pipeline=test
{
 "script": {
   "source": """
             ctx._source._routing = 1;
             """
 },
 "query": {
   "match": {
     "text": "aaa"
   }
 }
}

```

So I successfully updated routing，I want to know why

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 6, 2020, 6:38am UTC](https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951/2 "2020-07-06T06:38:36Z")

</div>

I believe this is due to the point at which the scripts are executed. Pipelines run on an ibgest node and are then routed to the appropriate primary shards, which is why the parameters can be set there. A scripted update is run on the node holding the primary shard once routing has already been performed. You can therefore not change it at that point.

---

<div class="post-metadata">

**Author:** ![FFFro](https://avatars.discourse-cdn.com/v4/letter/f/8c91f0/32.png) [@FFFro](https://discuss.elastic.co/u/FFFro)\
**Post date:** [July 7, 2020, 9:30am UTC](https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951/3 "2020-07-07T09:30:46Z")

</div>

Thank you for your answer. Your answer is very good.

---

<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:** [August 4, 2020, 9:30am UTC](https://discuss.elastic.co/t/the-difference-between-using-script-in-pipeline-and-using-normal-script-to-update-document/239951/4 "2020-08-04T09:30:48Z")

</div>

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