【问题标题】:Elasticsearch MapperParsingException[failed to parse, document is empty] during indexingElasticsearch MapperParsingException [无法解析,文档为空] 在索引期间
【发布时间】:2014-09-03 05:11:53
【问题描述】:

我正在使用带有 php wrapper elastica 的 elasticsearch 1.2.2

在索引一些文档时遇到以下异常

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

现在解析失败的就是这个明显不为空的文档。

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

文档映射是这样的

$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), 

));

按照此处的建议以批量模式进行索引 elatica.io: Bulk indexing

我很确定这是由 字符引起的。不确定是否需要转义。如果确实如此,我该如何转义这些字符?

【问题讨论】:

  • 你能分享你做批量请求的代码吗?

标签: php elasticsearch elastica


【解决方案1】:

解决了。这是一个编码问题。我的数据来自 mysql 服务器,我必须在 pdo 对象初始化期间设置正确的字符集选项。

【讨论】:

  • 那是什么字符集?
【解决方案2】:

由于特殊字符,这是一个编码问题,我建议您转义您尝试使用索引的文本

$text = html_entity_decode(htmlentities($text, ENT_IGNORE, "UTF-8"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 2020-02-23
    • 1970-01-01
    相关资源
    最近更新 更多