I am working with Elasticsearch in lumen for simple search.
I followed Elastic search installation tutorial from : https://medium.com/@basemkhirat_88244/laravel-lumen-flexible-elasticsearch-query-builder-inspired-from-eloquent-bb5221c65af8
And In my 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);
}
And in my routes.php file
$app->get('/search', 'Controller@search');
My es.php configuration file :
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'
]
]
]
]
]
]
];
When running /search link in browser it shows result array like
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
)
)
My Question is Why My Items array is empty even though there is data with name = Leena Patel ?
Please help! I am learning ElasticSearch!
from Elasticsearch in lumen giving empty Items in Resulted Data
No comments:
Post a Comment