dev-master
9999999-develasticsearch client for php
MIT
The Requires
by Lee Vinkim
v0.0.3
0.0.3.0elasticsearch client for php
MIT
The Requires
by Lee Vinkim
v0.0.2
0.0.2.0elasticsearch client for php
MIT
The Requires
by Lee Vinkim
Wallogit.com
2017 © Pedro Peláez
elasticsearch client for php
使用 PHP 对 Elasticsearch 做索引管理,以及索引新文档, (*1)
$ composer install
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;
$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);
$db = 'test';
$collection = 'user';
$properties = [
'name' => a['type' => 'string'],
'age' => ['type' => 'integer'],
'balance' => ['type' => 'double'],
'create_at' => ['type' => 'date']
];
// 更多 mapping type 见官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/mapping-types.html
$writer->setNamespace($db, $collection)->putMapping($properties);
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;
$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);
$db = 'test';
$collection = 'user';
$properties = [
'name' => ['type' => 'string'],
'age' => ['type' => 'integer'],
'balance' => ['type' => 'double'],
'create_at' => ['type' => 'date']
];
$document = [
'id'=> '59c1cfb9a008b',
'name' => 'lvinkim-'.rand(1,1000),
'age' => rand(10,90),
'balance' => rand(0,1000),
'create_at' => time()
];
$writer->setNamespace($db, $collection);
// 手动指定 mapping 字段的类型,如果不手动指定,将由 Elasticsearch 自动生成
$writer->putMapping($properties);
$response = $writer->indexSingleDocument($document);
print_r($response);
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;
$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);
$db = 'test';
$collection = 'user';
$properties = [
'name' => ['type' => 'string'],
'age' => ['type' => 'integer'],
'balance' => ['type' => 'double'],
'create_at' => ['type' => 'date']
];
$documents = genDocuments();
$writer->setNamespace($db, $collection);
// 手动指定 mapping 字段的类型,如果不手动指定,将由 Elasticsearch 自动生成
$writer->putMapping($properties);
$writer->indexMultiDocuments($documents);
function genDocuments()
{
for ($i = 0; $i < 10000; $i++) {
$document = [
'id' => $i . '-' . uniqid(),
'name' => 'lvinkim-' . rand(1, 1000),
'age' => rand(10, 90),
'balance' => rand(0, 1000),
'create_at' => time()
];
yield $document;
}
}
elasticsearch client for php
MIT
elasticsearch client for php
MIT
elasticsearch client for php
MIT