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

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.".

But when I use a pipeline casually,like

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

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.

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

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