Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic bulk error: failed to parse

I tried posting a _bulk post into elastic search, but it throws:

{
   "took": 1,
   "errors": true,
   "items": [
      {
         "index": {
            "_index": "quick",
            "_type": "parts",
            "_id": "ACI250-2016",
            "status": 400,
            "error": {
               "type": "mapper_parsing_exception",
               "reason": "failed to parse [part]",
               "caused_by": {
                  "type": "number_format_exception",
                  "reason": "For input string: \"250-2016\""
               }
            }
         }
      }
   ]
}

And here's what I'm trying to post:

POST _bulk
{"index":{"_index":"quick","_type":"parts","_id":"ACI250-2016"}}
{"eMfg":"ACI","part":"250-2016"}

And the map is:

{
   "quick": {
      "mappings": {
         "parts": {
            "properties": {
               "app": {
                  "type": "string"
               },
               "eMfg": {
                  "type": "string"
               },
               "fPart": {
                  "type": "long"
               },
               "oPart": {
                  "type": "string"
               },
               "ofPart": {
                  "type": "string"
               },
               "part": {
                  "type": "long"
               },
               "price": {
                  "type": "double"
               },
               "title": {
                  "type": "string"
               }
            }
         }
      }
   }
}
like image 857
Jared Dunham Avatar asked Jan 12 '16 14:01

Jared Dunham


1 Answers

According to your mapping, part has type long and you're trying to send "250-2016". The reason might be that you've sent a document at some point with a part that was coercible to a number, e.g. "250" and now you're trying to send a string and it fails.

The best way is to use the mapping above to define a new index with the correct mapping type (see below) and then you can try your bulk import again.

DELETE /quick

PUT /quick
{
      "mappings": {
         "parts": {
            "properties": {
               "app": {
                  "type": "string"
               },
               "eMfg": {
                  "type": "string"
               },
               "fPart": {
                  "type": "long"
               },
               "oPart": {
                  "type": "string"
               },
               "ofPart": {
                  "type": "string"
               },
               "part": {
                  "type": "string"       <-- change this
               },
               "price": {
                  "type": "double"
               },
               "title": {
                  "type": "string"
               }
            }
         }
      }
}
like image 135
Val Avatar answered Oct 16 '22 21:10

Val