计算机学习

您现在的位置是:首页 > Elasticsearch8.0 > php-client > 正文

php-client

开始

hhb2025-01-19php-client32
创建索引$client = ClientBuilder::create()->build();$params = [  &nb

创建索引

$client = ClientBuilder::create()->build();
$params = [
    'index' => 'my_index'
];

// Create the index
$response = $client->indices()->create($params);

索引文档

$params = [
    'index' => 'my_index',
    'body'  => [ 'testField' => 'abc']
];

// Document will be indexed to my_index/_doc/<autogenerated ID>
$response = $client->index($params);

获取文档

$params = [
    'index' => 'my_index',
    'id'    => 'my_id'
];

// Get doc at /my_index/_doc/my_id
$response = $client->get($params);

搜索文档

$params = [
    'index' => 'my_index',
    'body'  => [
        'query' => [
            'match' => [
                'testField' => 'abc'
            ]
        ]
    ]
];

$results = $client->search($params);

更新文档

下面是更新文档的方法,例如添加一个新字段:

$params = [
    'index' => 'my_index',
    'id'    => 'my_id',
    'body'  => [
        'doc' => [
            'new_field' => 'abc'
        ]
    ]
];

// Update doc at /my_index/_doc/my_id
$response = $client->update($params);

删除文档

$params = [
    'index' => 'my_index',
    'id'    => 'my_id'
];

// Delete doc at /my_index/_doc_/my_id
$response = $client->delete($params);

删除索引

$params = ['index' => 'my_index'];
$response = $client->indices()->delete($params);


发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~