5.elasticsearch-php索引文档搜索文档

索引文档
搜索文档

<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->build();
// 获取文档
$params = [
    'index' => 'my_user',
    'type' => 'my_user',
    'id' => 1
];
// http://localhost:9200/my_user/my_user/1
// $response = $client->get($params);
// print_r($response);
// 搜索文档
$params = [
    'index' => 'my_user',
    'type' => 'my_user',
    'body' => [
        'query' => [
            'match' => [
                'name' => '张三'
            ]
        ]
    ]
];
$results = $client->search($params);
print_r($results);
echo "<hr/>".PHP_EOL;
$params = [
    'index' => 'my_user',
    'type' => 'my_user',
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    [ 'match' => [ 'name' => '张三' ] ],
                ]
            ]
        ]
    ]
];
$results = $client->search($params);
print_r($results);


发布了77 篇原创文章 · 获赞 33 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_39337886/article/details/103802019