Cant index field with ingest pipeline

Hello,

I am facing the following issue

Steps:

  1. I am creating without problem the following ingest pipeline:

     PUT _ingest/pipeline/alexpipeline
     {
       "description" : "calculate for the field http.request.body.original  the number of articles",
       "processors" : [
         {
           "script" : {
              "source": """
              
                   ctx.number_of_articles = ctx.http.request.body.original.items.length;
              
              """
           }
         }
       ]
     }
    
  2. I am creating without problem the following index:

     PUT /test3
     {
       "settings": {
         "number_of_shards": 1,
         "number_of_replicas": 1,
         "default_pipeline": "alexpipeline"
       },
       "mappings": {
         "properties": {
           "http": {
             "properties": {
               "request": {
                 "properties": {
                   "body": {
                     "properties": {
                       "original": {
                         "type": "nested",
                         "properties": {
                           "ArticleNr": {
                             "type": "text"
                           },
                           "items": {
                             "type": "nested",
                             "properties": {
                               "articleId": {
                                 "type": "text"
                               },
                               "quantity": {
                                 "type": "text"
                               }
                             }
                           }
                         }
                       }
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
    
  3. I try to index the following document

PUT /test3/_doc/1
{

"http.request.body.original":

{"ArticleNr":"471776","sendMethod":"TOUR","partialDelivery":false,"isTourTimetable":false,"deliveryAddressId":"1000000028658646379","items":[{"articleId":1001223455,"quantity":1},{"articleId":1001058014,"quantity":1},{"articleId":1001058015,"quantity":1},{"articleId":1001058019,"quantity":1},{"articleId":1001058017,"quantity":1}]}

}

BUT i get the exact error message below:

    {
      "error" : {
        "root_cause" : [
          {
            "type" : "script_exception",
            "reason" : "runtime error",
            "script_stack" : [
              "ctx.number_of_articles = ctx.http.request.body.original.items.length;\r\n         \r\n         ",
              "                                 ^---- HERE"
            ],
            "script" : " ...",
            "lang" : "painless",
            "position" : {
              "offset" : 60,
              "start" : 27,
              "end" : 118
            }
          }
        ],
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "ctx.number_of_articles = ctx.http.request.body.original.items.length;\r\n         \r\n         ",
          "                                 ^---- HERE"
        ],
        "script" : " ...",
        "lang" : "painless",
        "position" : {
          "offset" : 60,
          "start" : 27,
          "end" : 118
        },
        "caused_by" : {
          "type" : "null_pointer_exception",
          "reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
        }
      },
      "status" : 400
    }

How can i change the ingest pipeline code so that doesnt throw an error when trying to index my field?

IMPORTANT NOTE: If i dont use the ingest pipeline in the index settings and try to index the document no problem occurs. So i believe i must change something in my ingest pipeline script....

Best regards,

Alexandros

The "shorthand" dot notation syntax you are using to post the doc does not wortk with processors.

PUT /test3/_doc/1
{

"http.request.body.original": <!--- Here

See here for an explanation

Try this...

PUT /test3/_doc/1
{
  "http": {
    "request": {
      "body": {
        "original": {
          "ArticleNr": "471776",
          "sendMethod": "TOUR",
          "partialDelivery": false,
          "isTourTimetable": false,
          "deliveryAddressId": "1000000028658646379",
          "items": [
            {
              "articleId": 1001223455,
              "quantity": 1
            },
            {
              "articleId": 1001058014,
              "quantity": 1
            },
            {
              "articleId": 1001058015,
              "quantity": 1
            },
            {
              "articleId": 1001058019,
              "quantity": 1
            },
            {
              "articleId": 1001058017,
              "quantity": 1
            }
          ]
        }
      }
    }
  }
}


GET test3/_doc/1
{
  "_index" : "test3",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "http" : {
      "request" : {
        "body" : {
          "original" : {
            "isTourTimetable" : false,
            "deliveryAddressId" : "1000000028658646379",
            "ArticleNr" : "471776",
            "sendMethod" : "TOUR",
            "partialDelivery" : false,
            "items" : [
              {
                "quantity" : 1,
                "articleId" : 1001223455
              },
              {
                "quantity" : 1,
                "articleId" : 1001058014
              },
              {
                "quantity" : 1,
                "articleId" : 1001058015
              },
              {
                "quantity" : 1,
                "articleId" : 1001058019
              },
              {
                "quantity" : 1,
                "articleId" : 1001058017
              }
            ]
          }
        }
      }
    },
    "number_of_articles" : 5
  }
}
1 Like

Hello Stephen. it worked perfectly!!!!!!!!!!!!!!! Thank you very much !!!!!!!!!!!!!!!!!!!!!!!! :slight_smile:

1 Like