流明中的 Elasticsearch 在结果数据中给出空项目

Elasticsearch in lumen giving empty Items in Resulted Data

我正在 lumen 中使用 Elasticsearch 进行简单搜索。

我遵循了 Elastic 搜索安装教程:https://medium.com/@basemkhirat_88244/laravel-lumen-flexible-elasticsearch-query-builder-inspired-from-eloquent-bb5221c65af8

在我的 controller.php

public function search() {
    $users = \Basemkhirat\Elasticsearch\Facades\ES::index('user_index')->type("text")->body([
        "query" => [
             "bool" => [
                 "must" => [
                     [ "match" => [ "name" => "Leena Patel" ] ],
                 ]
             ]
         ]
    ])->get();
    dd($users);        
}

并且在我的 routes.php 文件中

$app->get('/search', 'Controller@search');

我的 es.php 配置文件:

return [

'default' => env('ELASTIC_CONNECTION', 'default'),

'connections' => [

    'default' => [

        'servers' => [

            [
                "host" => env("ELASTIC_HOST", "127.0.0.1"),
                "port" => env("ELASTIC_PORT", 9200),
                'user' => env('ELASTIC_USER', ''),
                'pass' => env('ELASTIC_PASS', ''),
                'scheme' => env('ELASTIC_SCHEME', 'http'),
            ]

        ],

        'index' => env('ELASTIC_INDEX', 'user_index'),

        // Elasticsearch handlers
        // 'handler' => new MyCustomHandler(),
    ]
],

'indices' => [

    'user_index' => [

        "aliases" => [
            "user_index_alias"
        ],

        'settings' => [
            "number_of_shards" => 1,
            "number_of_replicas" => 0,
        ],

        'mappings' => [
            'users_schema' => [
                "properties" => [
                    'name' => [
                        'type' => 'text'
                    ]
                ]
            ]
        ]

    ]

]

];

当 运行 /search link 在浏览器中显示结果数组如

Basemkhirat\Elasticsearch\Collection Object
(
    [items:protected] => Array
        (
        )

    [total] => 0
    [max_score] => 
    [took] => 1
    [timed_out] => 
    [scroll_id] => 
    [shards] => stdClass Object
        (
            [total] => 1
            [successful] => 1
            [skipped] => 0
            [failed] => 0
        )

)

我的问题是 为什么我的项目数组是空的,即使有名称为 Leena Patel 的数据?

请帮忙!我正在学习 ElasticSearch!

编辑:

我的数据库 table 包含列名和数据的用户 Leena Patel 所以我希望在我的项目结果中有这条记录

请使用下面的 link 进行弹性搜索

https://appdividend.com/2018/06/30/laravel-elasticsearch-tutorial-example/

然后按照以下步骤获得流明

1) Move config directory to root alongside with app folder

vendor\elasticquent\elasticquent\src\config

2) Remove comment from `$app->withEloquent();` in bootstrap\app.php of lumen folder
3) Register elasticquent in app.php file of lumen folder as below

$app->configure('elasticquent');

4) Run command in your lumen folder

composer dump-autoload

完成这些步骤后,您需要在 lumen 文件夹web.php 中设置路线

use App\Article;    // Use at top of web.php

$router->get('article', function() {

    Article::createIndex($shards = null, $replicas = null); // Using this code create command 
    Article::reindex(); // Reindex article indices

    $articles = Article::searchByQuery(['match' => ['title' => 'Android']]);   
    return $articles;
});