我正在尝试在弹性搜索中批量上传,我正在尝试插入的每条记录都收到此错误。 请帮帮我。
{"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和elasticsearch驱动程序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",$ids,$params); ?>
答案 0 :(得分:0)
您没有正确构建$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);
答案 1 :(得分:0)
我解决了这个问题,因为我使用的是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);