Conditionally Apply Attachment Processor

Hi all, first time posting in this forum. I have trouble writing the condition to apply the attachment processor. Below is the wrong configuration of the pipeline:

PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information from arrays",
  "processors" : [
    {
      "foreach": {
        "field": "attachments",
        "processor": {
          "attachment": {
            **"if": "ctx?.attachments.data != null",**
            "target_field": "_ingest._value.attachment",
            "field": "_ingest._value.data"
          }
        }
      }
    },{
      "foreach": {
        "field": "attachments",
        "remove": {
          "attachment": {
            **"if": "ctx?.attachments.data != null",**
            "field": "_ingest._value.data"
          }
        }
      }
    }
  ]
}

Have been brute forcing various ways to access the data field but to no avail or failed to apply the pipeline if somehow managed to access it.

Below is a sample data to ingest:

PUT my-index-000001/_doc/my_id?pipeline=attachment
{
  "attachments" : [
    {
      "filename" : "ipsum.txt",
      "data" : "dGhpcyBpcwpqdXN0IHNvbWUgdGV4dAo="
    },
    {
      "filename" : "test.txt"
    }
  ]
}

Expected:

{
  "_index" : "my-index-000001",
  "_id" : "my_id",
  "_version" : 1,
  "_seq_no" : 50,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "attachments" : [
      {
        "filename" : "ipsum.txt",
        "attachment" : {
          "content_type" : "text/plain; charset=ISO-8859-1",
          "language" : "en",
          "content" : "this is\njust some text",
          "content_length" : 24
        }
      },
      {
        "filename" : "test.txt"
      }
    ]
  }
}

Thank you all in advance!

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