Fail to index a document: mapper_parsing_exception: failed to parse, document is empty


(Vukasin Jockovic) #1

I really do not understand what is the problem here...

  1. I'm just testing simple Elasticsearch-php
  2. There's no big data to transfer or anything similar
  3. Just want to index one simple document via Elasticsearch-php
  4. When I add document via POST from KIBANA, everything works AND than I'm able to read it with php $client->get($params)
  5. When I add document from php ($client->index($params)) I catch the error:
    "mapper_parsing_exception: failed to parse, document is empty"

My $params:
$params = array(
'index' => 'sale',
'type' => 'pop',
'id' => '2',
'body' => array(
'name' => 'text...text...text'
)
);

My 'sale' mappings:
{
"sale": {
"mappings": {
"pop": {
"properties": {
"name": {
"type": "text"
}
}
}
}
}
}

Connection with the ES is ok; Get method works; Index is created and mapped; Only indexing with php throws and error:
"mapper_parsing_exception: failed to parse, document is empty"

Thank you....


(David Pilato) #2

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Impossible to tell without seeing what is exactly sent to elasticsearch.
Can you print/debug what is happening on the HTTP layer so we have a better idea?
What is the whole code?

May be first try to do it with pure REST calls (without PHP) and then do it using PHP?
Kibana Console will help you to do so. See an example in this guide.


(Vukasin Jockovic) #3

Thx for the fast response...

I am using Kibana already and everything works perfectly (PUT/POST/GET etc...) when I send request from Kibana Console. That's fine. But I do not need that; my goal is to index new documents with php (because I'm using wordpress and i want part of the content of my posts to go to ES because i need search function on my website and do not want to use mysql search functions).
Right now I'm just testing php functions and ES, but for some reason ->index() doesen't do the work it is provided to...

  1. Like I said, error is: "mapper_parsing_exception: failed to parse, document is empty", please tell me when ES throws this exception, what is generally a problem when this exception occures?

  2. Request I'm sending to ES is:

     $params = array(
        'index' => 'sale',
        'type' => 'pop',
        'id' => '2',
        'body' => array(
            'name' => 'text...text...text'
        )
      );	
    
  3. Index is alredy made and MAPPED using Kibana Console; here's the mapping :

      {
        "sale": {
          "mappings": {
            "popusti": {
              "properties": {
                 "name": {
                    "type": "keyword"
               }
             }
           }
         }
       }

(Vukasin Jockovic) #4
  1. Thrown error:

Bad Request [body] => {"error":
{"root_cause":[{
"type":"mapper_parsing_exception" ,
"reason":"failed to parse, document is empty"
}],
"type":"mapper_parsing_exception",
"reason":"failed to parse, document is empty"
},"status":400} )


(Vukasin Jockovic) #5

There is mistype in mapping, sry:
Request:
'type' => 'pop'

and in mapping:
"mappings": {
"pop" : { etc. }
}

but this is just mistype here while writing, not the cause of the problem...i had to point out just to not confuse anybody...sry


(David Pilato) #6

I'm not ready PHP code but may be the error is that you are sending something like:

[
  "..."
]

instead of

{
  "..."
}

But again, displaying what is sent on a HTTP layer would help.


(lukasSirhal) #7

Hello i have alike problem. After i finally instaled and ran x-pack. I stuck on index problem. I use PL/SQL to create json from DB data. After i create whole json document i send it via HTTP POST to REST.

http://elastic:changeme@our_server:port/spm/spm-order/29289

json:

   {
	"primaryKey": 29289,
	"orderVersion": 1,
	"note": "Objednávka z SPM (messageId=ParallelOrderTest-jenkins-7071c0e7-f71f-4791-8ffa-5b5784c3e3fc): crmOrderId=ParallelOrderTest_TS7LJN4QI, technicalOrderId=ParallelOrderTest_TS7LJN4QM-pool-1-thread-90, "
	"offerId": null,
	"serviceId": null,
	"orderAction": "ADD",
	"crmOrderId": "ParallelOrderTest_TS7LJN4QI",
	"technicalOrderId": "ParallelOrderTest_TS7LJN4QM-pool-1-thread-90",
	"priority": 3,
	"operator": "O2_CZ",
	"cacRefNo": "5900000461",
	"dateCreated": "02.12.2016 09:25:44",
	"dateNeeded": null,
	"dateRealization": null,
	"lastModifTs": null,
	"objednatelIco": "x2579555",
	"objednatelName": "Michal Pavlusek",
	"serviceItem": [{
		"akce": "ADD",
		"hlavniAtribut": "TARIFF_FREE_EU_D_L",
		"processId": 91762,
		"spmId": 311168,
		"parentSpmId": 304928,
		"productInstanceId": "TS7LJN4QL-pool-1-thread-90",
		"crossId": null,
		"serviceOrderId": 29289,
		"parentServiceItemId": null,
		"state": "ACTIVE",
		"active": "PROJECT",
		"specClassifier": "TARIFF_SPACE",
		"tariffSpaceAttribut": "TARIFF_FREE_EU_D_L",
		"specNazev": "TariffSpace",
		"specProductCode": "TARIFF_SPACE",
		"specProductCategory": "TARIFF_SPACE",
		"ktt": {},
		"serviceItemParam": []
	}]
}

mapping:

{
"settings": {
	"number_of_shards": "1",
	"number_of_replicas": "1",
	"index": {
		"analysis": {
			"analyzer": {
				"lowerCaseCzechAnalyzer": {
					"type": "custom",
					"filter": [
						"trim",
						"czech_stop_words",
						"czech_standard",
						"lowercase"
					],
					"tokenizer": "keyword"
				}
			},
			"filter": {
				"czech_stop_words": {
					"type": "stop",
					"stopwords": [
						"_czech_"
					]
				},
				"custom_word_delimiter": {
					"preserve_original": "true",
					"type": "word_delimiter"
				},
				"czech_standard": {
					"type": "standard",
					"name": "czech"
				}
			}
		},
		"mapper": {
			"dynamic": "false"
		}
	}
},
"mappings": {
	"spm-order": {
		"properties": {
			"cacRefNo": {
				"type": "keyword",
				"store": true
			},
			"crmOrderId": {
				"type": "text",
				"analyzer": "lowerCaseCzechAnalyzer",
				"store": true
			},
			"dateCreated": {
				"type": "date",
				"format": "dd.MM.yyyy HH:mm:ss",
				"store": true
			},
			"dateNeeded": {
				"type": "date",
				"format": "dd.MM.yyyy HH:mm:ss"
			},
			"dateRealization": {
				"type": "date",
				"format": "dd.MM.yyyy HH:mm:ss"
			},
			"lastModifTs": {
				"type": "date",
				"format": "dd.MM.yyyy HH:mm:ss"
			},
			"note": {
				"type": "text",
				"analyzer": "lowerCaseCzechAnalyzer"
			},
			"offerId": {
				"type": "keyword",
				"store": true
			},
			"operator": {
				"type": "keyword"
			},
			"orderAction": {
				"type": "keyword",
				"store": true
			},
			"primaryKey": {
				"type": "long",
				"store": true
			},
			"priority": {
				"type": "short",
				"store": true
			},
			"serviceId": {
				"type": "keyword",
				"store": true,
				"fields": {
					"text": {
						"type": "text"
					}
				}
			},
			"objednatelIco": {
				"type": "keyword"
			},
			"objednatelName": {
				"type": "keyword"
			},
			"serviceItem": {
				"type": "nested",
				"properties": {
					"active": {
						"type": "keyword",
						"store": true
					},
					"akce": {
						"type": "keyword",
						"store": true
					},
					"crossId": {
						"type": "keyword",
						"store": true
					},
					"hlavniAtribut": {
						"type": "keyword",
						"store": true
					},
					"parentServiceItemId": {
						"type": "long",
						"store": true,
						"fields": {
							"text": {
								"type": "text"
							}
						}
					},
					"parentSpmId": {
						"type": "long",
						"fields": {
							"text": {
								"type": "text"
							}
						}
					},
					"processId": {
						"type": "long"
					},
					"productInstanceId": {
						"type": "keyword"
					},
					"serviceAssoc": {
						"type": "nested",
						"properties": {
							"classifier": {
								"type": "keyword"
							},
							"serviceAssocId": {
								"type": "long"
							},
							"serviceInstanceId": {
								"type": "long"
							}
						}
					},
					"serviceItemParam": {
						"type": "nested",
						"properties": {
							"paramNazevValue": {
								"type": "keyword",
								"store": true
							}
						}
					},
					"basicServiceAttribut": {
						"type": "keyword",
						"store": true
					},
					"technologyPointAttribut": {
						"type": "keyword",
						"store": true
					},
					"specNazev": {
						"type": "keyword",
						"store": true
					},
					"specProductCategory": {
						"type": "keyword",
						"store": true
					},
					"specProductCode": {
						"type": "keyword",
						"store": true
					},
					"spmId": {
						"type": "long",
						"store": true,
						"fields": {
							"text": {
								"type": "text"
							}
						}
					},
					"state": {
						"type": "keyword",
						"store": true
					}
				}
			},
			"statusId": {
				"type": "long"
			},
			"technicalOrderId": {
				"type": "keyword",
				"store": true
			}
		}
	}
}

}

If i get

status code: 400 content: {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"}],"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"},"status":400} json: ....

when i copy JSON and post it via kibana dev tools it's works fine.


(Vukasin Jockovic) #8

Hello lukasSirhal1,

It's a really weird problem, but I solved it with Elastica.io...
I'm little bit sad because not using offical php-api, but anyway it solved my problems.

Works like charm now :smiley:


(lukasSirhal) #9

But i have this trouble while i send http post via UTL_HTTP oracle function :slight_smile:


(lukasSirhal) #10

Problem solved, it was stupid erorr.

When you use x-pack you have to create url like this:

http://elastic:changeme@your_server:port/.....

if you create this POST via PL/SQL authentication, you set login, passwd to header so you create url without basic auth.


(system) #11

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