Elasticsearch MapperParsingException[failed to parse, document is empty] during indexing

user80287 picture user80287 · Jul 12, 2014 · Viewed 15.9k times · Source

I am using elasticsearch 1.2.2 with php wrapper elastica

while indexing some documents i encountered the following exception

PHP Fatal error:  Uncaught exception 'Elastica\Exception\Bulk\ResponseException' with message 'Error in one or more bulk request actions:

index: /en_search/en_msg/936 caused MapperParsingException[failed to parse, document is empty]
' in /root/search/vendor/ruflin/elastica/lib/Elastica/Bulk.php:395
Stack trace:
#0 /root/search/vendor/ruflin/elastica/lib/Elastica/Bulk.php(345): Elastica\Bulk->_processResponse(Object(Elastica\Response))
#1 /root/search/vendor/ruflin/elastica/lib/Elastica/Client.php(284): Elastica\Bulk->send()
#2 /root/search/vendor/ruflin/elastica/lib/Elastica/Index.php(147): Elastica\Client->addDocuments(Array)
#3 /root/search/vendor/ruflin/elastica/lib/Elastica/Type.php(187): Elastica\Index->addDocuments(Array)
#4 /root/search/setData.php(36): Elastica\Type->addDocuments(Array)
#5 {main}
  thrown in /root/search/vendor/ruflin/elastica/lib/Elastica/Bulk.php on line 395

Now the the document that it fails to parse is this one which is obviously not empty.

array(
    [id] => 936
    [uid] => 3222
    [msid] => 211
    [login] => user1222
    [msg] => Wouldn’t you love a cup right now?
)

document mapping was something like this

$mapping->setProperties(array(
    'id'  => array('type' => 'integer', 'include_in_all' => true),
    'uid' => array('type' => 'integer', 'include_in_all' => true),
    'msid' => array('type' => 'integer', 'include_in_all' => true),
    'login' => array('type' => 'string', 'include_in_all' => TRUE),
    'msg'  => array('type' => 'string', 'include_in_all' => true), 

));

doing indexing in bulk mode as suggested here elatica.io: Bulk indexing

i am pretty sure it's caused by character. Not sure if it requires escaping . in case it does how do i escape such characters?

Answer

user80287 picture user80287 · Jul 14, 2014

Solved . it was an encoding problem. my data was coming from mysql server , i had to set the correct charset option during pdo object initialization.