# Question about nested pipeline

**URL:** <https://discuss.elastic.co/t/question-about-nested-pipeline/291400>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 10, 2021, 8:26am UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400 "2021-12-10T08:26:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fengjian1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fengjian1993/32/98668_2.png) [@fengjian1993](https://discuss.elastic.co/u/fengjian1993)\
**Post date:** [December 10, 2021, 8:26am UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/1 "2021-12-10T08:26:38Z")

</div>

I have question with using nested pipeline 😉

1. distribution pipeline processor:  
PUT \_ingest/pipeline/pipeline\_for\_distribution  
{  
"description": "a pipeline for distribution",  
"processors": [  
{  
"pipeline": {  
"name": "pipeline\_for\_set",  
"if": """  
String tagss = ctx['tags'];  
if (tagss.toLowerCase().contains('openstack')) {  
return true;  
}  
return false;  
"""  
}  
},  
{  
"pipeline": {  
"name": "pipeline\_for\_split",  
"if": """  
String tagsx = ctx['tags'];  
if (tagsx.toLowerCase().contains('hadoop')) {  
return true;  
}  
return false;  
"""  
}  
}  
]  
}
2. Nested pipeline processor  
PUT \_ingest/pipeline/pipeline\_for\_set  
{  
"description": "a pipeline for set",  
"processors": [  
{  
"pipeline": {  
"name": "pipeline\_for\_split"  
}  
}  
]  
}
3. Normal pipeline processor  
PUT \_ingest/pipeline/pipeline\_for\_split  
{  
"description": "a pipeline for split",  
"processors": [  
{  
"split": {  
"field": "tags",  
"separator": ",",  
"target\_field": "tags\_arr" //if no target\_field set, will be failed  
}  
}  
]  
}
4. Test  
POST \_ingest/pipeline/\_simulate  
{  
"pipeline": {  
"description": "to split blog tags",  
"processors": [  
{  
"pipeline": {  
"name": "pipeline\_for\_distribution"  
}  
}  
]  
},  
"docs": [  
{  
"\_index": "index",  
"\_id": "idxx",  
"\_source": {  
"title": "Introducing cloud computering",  
"tags": "openstack,k8s",  
"content": "You konw,for cloud"  
}  
}  
]  
}
5. Error  
{  
"docs" : [  
{  
"error" : {  
"root\_cause" : [  
{  
"type" : "exception",  
"reason" : "java.lang.IllegalArgumentException: ScriptException[runtime error]; nested: ClassCastException[org.Elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",  
"header" : {  
"processor\_type" : "conditional"  
}  
}  
],  
"type" : "exception",  
"reason" : "java.lang.IllegalArgumentException: ScriptException[runtime error]; nested: ClassCastException[org.Elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",  
"caused\_by" : {  
"type" : "illegal\_argument\_exception",  
"reason" : "ScriptException[runtime error]; nested: ClassCastException[org.Elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",  
"caused\_by" : {  
"type" : "script\_exception",  
"reason" : "runtime error",  
"script\_stack" : [  
"""  
tagsx = ctx['tags'];

""",  
" ^---- HERE"  
],  
"script" : """  
String tagsx = ctx['tags'];  
if (tagsx.toLowerCase().contains('hadoop')) {  
return true;  
}  
return false;  
""",  
"lang" : "painless",  
"caused\_by" : {  
"type" : "class\_cast\_exception",  
"reason" : "org.Elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String"  
}  
}  
},  
"header" : {  
"processor\_type" : "conditional"  
}  
}  
}  
]  
}

Anyone can help me to explain this?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 10, 2021, 5:49pm UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/2 "2021-12-10T17:49:32Z")

</div>

Hi @fengjian1993 Welcome to the community.

Unfortunately it will be really difficult for people to help because we can not read your code because it is not formatted.

Could you please edit your post... And format your code...

You can select / highlight it using the `</>` button on the formatting bar

 ![Screen Shot 2021-12-10 at 9.48.28 AM](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6c30789633313e5c74df849084b0d4a473a39586.png)

Thanks then we might be able to help...

---

<div class="post-metadata">

**Author:** ![fengjian1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fengjian1993/32/98668_2.png) [@fengjian1993](https://discuss.elastic.co/u/fengjian1993)\
**Post date:** [December 28, 2021, 9:32am UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/3 "2021-12-28T09:32:26Z")

</div>

**distribution pipeline processor:**

```auto
PUT _ingest/pipeline/pipeline_for_distribution
{
    "description": "a pipeline for distribution",
    "processors": [
        {
            "pipeline": {
                "name": "pipeline_for_set",
                "if": """
                    String tagss = ctx['tags'];
                    if (tagss.toLowerCase().contains('openstack')) {
                        return true;
                    }
                    return false;
                """
            }
        },
        {
            "pipeline": {
                    "name": "pipeline_for_split",
                    "if": """
                        String tagsx = ctx['tags'];
                        if (tagsx.toLowerCase().contains('hadoop')) {
                            return true;
                        }
                        return false;
                    """
            }
        }
    ]
}

```

**Nested pipeline processor:**

```auto
PUT _ingest/pipeline/pipeline_for_set
{
    "description": "a pipeline for set",
    "processors": [
        {
            "pipeline": {
                "name": "pipeline_for_split"
            }
        }
    ]
}

```

**Normal pipeline processor:**

```auto
PUT _ingest/pipeline/pipeline_for_split
{
    "description": "a pipeline for split",
    "processors": [
        {
            "split": {
                "field": "tags",
                "separator": ",",
                "target_field": "tags_arr" //if no target_field set, will be failed
            }
        }
    ]
}

```

**Test**

```auto
POST _ingest/pipeline/_simulate
{
    "pipeline": {
        "description": "to split blog tags",
        "processors": [
            {
                "pipeline": {
                    "name": "pipeline_for_distribution"
                }
            }
        ]
    },
    "docs": [
        {
            "_index": "index",
            "_id": "idxx",
            "_source": {
                "title": "Introducing cloud computering",
                "tags": "openstack,k8s",
                "content": "You konw,for cloud"
            }
        }
    ]
}

```

**Error**

```auto
{
  "docs" : [
    {
      "error" : {
        "root_cause" : [
          {
            "type" : "exception",
            "reason" : "java.lang.IllegalArgumentException: ScriptException[runtime error]; nested: ClassCastException[org.elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",
            "header" : {
              "processor_type" : "conditional"
            }
          }
        ],
        "type" : "exception",
        "reason" : "java.lang.IllegalArgumentException: ScriptException[runtime error]; nested: ClassCastException[org.elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",
        "caused_by" : {
          "type" : "illegal_argument_exception",
          "reason" : "ScriptException[runtime error]; nested: ClassCastException[org.elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String];",
          "caused_by" : {
            "type" : "script_exception",
            "reason" : "runtime error",
            "script_stack" : [
              """
tagsx = ctx['tags'];
                        
""",
              " ^---- HERE"
            ],
            "script" : """
                        String tagsx = ctx['tags'];
                        if (tagsx.toLowerCase().contains('hadoop')) {
                            return true;
                        }
                        return false;
""",
            "lang" : "painless",
            "caused_by" : {
              "type" : "class_cast_exception",
              "reason" : "org.elasticsearch.ingest.ConditionalProcessor$UnmodifiableIngestList cannot be cast to java.lang.String"
            }
          }
        },
        "header" : {
          "processor_type" : "conditional"
        }
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![fengjian1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fengjian1993/32/98668_2.png) [@fengjian1993](https://discuss.elastic.co/u/fengjian1993)\
**Post date:** [December 28, 2021, 9:33am UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/4 "2021-12-28T09:33:53Z")

</div>

Thanks for the reply, formatted issue has been posted above

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stu/32/75063_2.png) [@stu](https://discuss.elastic.co/u/stu)\
**Post date:** [January 5, 2022, 4:39pm UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/5 "2022-01-05T16:39:02Z")

</div>

@fengjian1993 Notice the pipeline is splitting tags on `,`:

```auto
PUT _ingest/pipeline/pipeline_for_split
{
    "description": "a pipeline for split",
    "processors": [
        {
            "split": {
                "field": "tags",
                "separator": ",",
                "target_field": "tags_arr" //if no target_field set, will be failed
            }
        }
    ]
}

```

And the script is getting an error at

```auto
String tagsx = ctx['tags'];

```

```auto
UnmodifiableIngestList cannot be cast to java.lang.String];

```

Which is due to `ctx['tags']` being a `List` of `String` after the split processor above.

Try moving if processor before the split processor or, in the if processor, iterate over the list of tags from `ctx['tags']` after it has been split.

---

<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:** [February 2, 2022, 4:39pm UTC](https://discuss.elastic.co/t/question-about-nested-pipeline/291400/6 "2022-02-02T16:39:17Z")

</div>

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