我正在尝试使用php客户端为使用Guzzle的 flex 搜索索引文档。编译完我的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);

10-08 13:46
查看更多