Es 全文 PHP 操作

 

1、删除对应的es 节点

$head = 'Content-Type: application/json';
$json = '';
$res = Curl_es("http://127.0.0.1:9200/my_index_2?pretty",'DELETE',$json,$head);

function Curl_es($url, $method, $data_string, $head)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($head));
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        print curl_error($ch);
    }
    curl_close($ch);
    return $result;
}

2、retrying failed action with response code: 403 ({"type"=>"cluster_block_exception", "reason"=>"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]

  这是由于ES新节点的数据目录data存储空间不足,导致从master主节点接收同步数据的时候失败,此时ES集群为了保护数据,会自动把索引分片index置为只读read-only

$head = 'Content-Type: application/json';
$json = '{
    "index":{
        "blocks":{
        "read_only_allow_delete":"false"
        }
    }}';
$res = Curl_es("http://10.10.1.136:9200/_settings?pretty", 'PUT', $json, $head);

3、es设置index.max_result_window(就是from+size,默认大小10000),可通过如下方式修改:

$head = 'Content-Type: application/json';
$json = '{
    "index":{
        "max_result_window": 10000000
    }}';
$res = Curl_es("http://10.10.1.136:9200/_settings?pretty", 'PUT', $json, $head);
echo $res;
posted @ 2019-08-09 14:53  Reset_90  阅读(972)  评论(0编辑  收藏  举报