Curl Exception 7 PHP and Guzzle with Elasticsearch


Curl Exception 7 PHP and Guzzle with Elasticsearch

我正在尝试使用使用Guzzle的弹性搜索php客户端索引文档。编译我的 php 脚本后,我收到一个错误,说内部服务器错误,代码 500。经过一些研究,这似乎是连接到服务器的问题,但奇怪的是,我尝试做的一切都是在同一台机器上设置的。我的 Elasticsearch 实例、我尝试索引的文档以及我的 php 脚本都保存并在同一台机器上运行。这是我的PHP脚本:

<?php
require '/home/aharmon/vendor/autoload.php';
$client = new Elasticsearch'Client();
$root = realpath('/home/aharmon/elkdata/for_elk_test_2014_11_24/Agencies');
$iter = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
    RecursiveIteratorIterator::SELF_FIRST,
    RecursiveIteratorIterator::CATCH_GET_CHILD);
$paths = array($root);
foreach ($iter as $path => $dir) {
if ($dir -> isDir()) {
    $paths[] = $path;
    }
}
//Create the index and mappings
$mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code
$mapping['body'] = array (
'mappings' => array (
    'documents' => array (
        '_source' => array (
            'enabled' => true
        ),
        'properties' => array(
            'doc_name' => array(
                'type' => 'string',
                'analyzer' => 'standard'
            ),
            'description' => array(
                'type' => 'string'
            )
        )
    )
)
);



//Now index the documents
for ($i = 0; $i <= 10000; $i++) {
    $params ['body'] [] = array(
    'index' => array(
        '_id' => $i
        )
    );
    $params ['body'] [] = array(
    'type' => 'documents',
    'body' => array(
        'foo' => 'bar'//Document body goes here
        )
    );

//Every 1000 documents stop and send the bulk request.
if($i % 1000) {
    $responses = $client->bulk($params);
// erase the old bulk request
$params = array();
// unset the bulk response when you are done to save memory
unset($responses);
}
}
$client ->indices()->create($mapping)
?>

如果有人以前看过这个或对什么问题有倾向,将不胜感激。当我尝试设置 SSH 时,我之前遇到了类似的问题,但我配置了所有防火墙并使 SSH 正常工作,所以我不确定为什么会发生这种情况。

检查此链接对我来说没问题:http://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_index_operations.html#_put_mappings_api

<?php
// Set the index and type
$params['index'] = 'my_index';
$params['type']  = 'my_type2';
// Adding a new type to an existing index
$myTypeMapping2 = array(
    '_source' => array(
        'enabled' => true
    ),
    'properties' => array(
        'first_name' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),
        'age' => array(
            'type' => 'integer'
        )
    )
);
$params['body']['my_type2'] = $myTypeMapping2;
// Update the index mapping
$client->indices()->putMapping($params);