Array of objects in pipeline

Hi i m trying to write a pipeline to find a missing field in an array of objects. So this is what i wrote.

PUT _ingest/pipeline/header-missing
{
  "description": "header missing",
  "version": 1,
 "processors" : [
    {
      "script" : {
        "source": """
        for (item in ctx.request_headers) {
          item.field_lower = item.header1;
          if(ctx.item?.header1 == null){
            item.field = "raj"
          }
          
          }
        """
      }
    }
  ]
}

Here is my simulate

POST /_ingest/pipeline/header-missing/_simulate?verbose
{
  "docs": [
    {
      "_index": "index",
      "_id": "id",
      "_source": {
        "request_headers": [
          {
            "header1": "one"
            
          },
          {
            "header2": "two"
            
          }
        ]
      }
    }
  ]
}

i think i m getting lost in finding value of an object. thus its printing "field " : "raj" on both fields. any help on what should i be doing ?

thanks

Raj

am i trying something wrong ? I have tried

"processor": {
          "set": {
            "field": "my_field",
            "value": "{{_ingest.header1._value}}"
            
          }
        }

just cant seem to figure this :frowning: All i m trying is if field is missing set my custom field and if field is there extract value and assign it to my custom field .

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