[英]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和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); ?>
<?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); ?>
您沒有正確構造$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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.