﻿---
title: Ingest processor context
description: Use a Painless script in an ingest processor to modify documents upon insertion. Variables Side Effects Return API Both the standard Painless API and...
url: https://www.elastic.co/elastic/docs-builder/docs/2510/reference/scripting-languages/painless/painless-ingest-processor-context
products:
  - Painless
---

# Ingest processor context
Use a Painless script in an [ingest processor](https://www.elastic.co/elastic/docs-builder/docs/2510/reference/enrich-processor/script-processor) to modify documents upon insertion.
**Variables**
<definitions>
  <definition term="params (Map, read-only)">
    User-defined parameters passed in as part of the query.
  </definition>
  <definition term="ctx['_index'] (String)">
    The name of the index.
  </definition>
  <definition term="ctx (Map)">
    Contains extracted JSON in a `Map` and `List` structure for the fields that are part of the document.
  </definition>
</definitions>

**Side Effects**
<definitions>
  <definition term="ctx['_index']">
    Modify this to change the destination index for the current document.
  </definition>
  <definition term="ctx (Map)">
    Modify the values in the `Map/List` structure to add, modify, or delete the fields of a document.
  </definition>
</definitions>

**Return**
<definitions>
  <definition term="void">
    No expected return value.
  </definition>
</definitions>

**API**
Both the standard [Painless API](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared.html) and [Specialized Ingest API](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-ingest.html) are available.
**Example**
To run this example, first follow the steps in [context examples](https://www.elastic.co/elastic/docs-builder/docs/2510/reference/scripting-languages/painless/painless-context-examples).
The seat data contains:
- A date in the format `YYYY-MM-DD` where the second digit of both month and day is optional.
- A time in the format HH:MM* where the second digit of both hours and minutes is optional. The star (*) represents either the `String` `AM` or `PM`.

The following ingest script processes the date and time `Strings` and stores the result in a `datetime` field.
```java
String[] dateSplit = ctx.date.splitOnToken("-");                     
String year = dateSplit[0].trim();
String month = dateSplit[1].trim();

if (month.length() == 1) {                                           
    month = "0" + month;
}

String day = dateSplit[2].trim();

if (day.length() == 1) {                                             
    day = "0" + day;
}

boolean pm = ctx.time.substring(ctx.time.length() - 2).equals("PM"); 
String[] timeSplit = ctx.time.substring(0,
        ctx.time.length() - 2).splitOnToken(":");                    
int hours = Integer.parseInt(timeSplit[0].trim());
int minutes = Integer.parseInt(timeSplit[1].trim());

if (pm) {                                                            
    hours += 12;
}

String dts = year + "-" + month + "-" + day + "T" +
        (hours < 10 ? "0" + hours : "" + hours) + ":" +
        (minutes < 10 ? "0" + minutes : "" + minutes) +
        ":00+08:00";                                                 

ZonedDateTime dt = ZonedDateTime.parse(
         dts, DateTimeFormatter.ISO_OFFSET_DATE_TIME);               
ctx.datetime = dt.getLong(ChronoField.INSTANT_SECONDS)*1000L;        
```

Submit the following request:
```json

{
  "description": "update datetime for seats",
  "processors": [
    {
      "script": {
        "source": "String[] dateSplit = ctx.date.splitOnToken('-'); String year = dateSplit[0].trim(); String month = dateSplit[1].trim(); if (month.length() == 1) { month = '0' + month; } String day = dateSplit[2].trim(); if (day.length() == 1) { day = '0' + day; } boolean pm = ctx.time.substring(ctx.time.length() - 2).equals('PM'); String[] timeSplit = ctx.time.substring(0, ctx.time.length() - 2).splitOnToken(':'); int hours = Integer.parseInt(timeSplit[0].trim()); int minutes = Integer.parseInt(timeSplit[1].trim()); if (pm) { hours += 12; } String dts = year + '-' + month + '-' + day + 'T' + (hours < 10 ? '0' + hours : '' + hours) + ':' + (minutes < 10 ? '0' + minutes : '' + minutes) + ':00+08:00'; ZonedDateTime dt = ZonedDateTime.parse(dts, DateTimeFormatter.ISO_OFFSET_DATE_TIME); ctx.datetime = dt.getLong(ChronoField.INSTANT_SECONDS)*1000L;"
      }
    }
  ]
}
```