Elasticsearch 无法解析异常 - 批量索引


Elasticsearch failed to parse exception-- bulk indexing

我正在尝试在弹性搜索中批量上传,我尝试插入的每条记录都收到此错误。请帮我解决这个问题。

{"took":2828,"errors":true,"items":[{"index":{"_index":"abc","_type":"abc","_id":"0","status":400,"error":{"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}}}}]}

这是我正在使用的代码我正在使用 5.3 和弹性搜索驱动程序 1.4 <?php require_once "/var/www/ElasticSearch/models/ElasticSearchModels.php"; $params = array(); $ids = array(); for($i=0;$i<10;$i++){ $ids[] = $i; $params[] = array("here"=>"here","temp"=>"temp","pr"=>$i); } $elasticSearch = new ElasticSearch(); $elasticSearch->saveInElasticSearchBulk("products_staging","products_staging",$i‌​ds,$params); ?>

您没有正确构造$params数组,它应该如下所示:

$params = array(); 
for($i = 0; $i < 10; $i++){
  $params['body'][] = array(
    'index' => array(
        '_index' => 'products_staging',
        '_type' => 'products_staging',
        '_id' => $i
    )
  );
  $params['body'][] = array(
    'here' => 'here',
    'temp' => 'temp',
    'pr' => $i
  );
}
$elasticSearch = new ElasticSearch(); 
$elasticSearch->saveInElasticSearchBulk($params); 

我解决了这个问题,因为我使用的是ElasticSearch php驱动程序1.4。批量 API 的语法完全不同。

$params = array(); 
for($i = 0; $i < 10; $i++){

$params['body'][] = array(
    'index' => array(
        '_index' => 'products_staging',
        '_type' => 'products_staging',
        '_id' => $i
    )
  );
  $params['body'][] = json_encode(array(
    'here' => 'here',
    'temp' => 'temp',
    'pr' => $i
  );)
}
$elasticSearch = new ElasticSearch(); 
$elasticSearch->saveInElasticSearchBulk($params);