Model return empty array
Opened this issue · 1 comments
ariesmaulana commented
i am using latest lumen, and this my configuration based on doc.
es.php
<?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', 'products_1'),
]
],
'indices' => [
'products_1' => [
"aliases" => [
"products"
],
'settings' => [
"number_of_shards" => 1,
"number_of_replicas" => 0,
],
'mappings' => [
'products' => [
"properties" => [
'title' => [
'type' => 'text'
]
]
]
]
]
]
];
i am change string
to text
because when i used string i got this error
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"No handler for type [string] declared on field [title]"}],
"type":"mapper_parsing_exception","reason":"No handler for type [string] declared on field [title]"},"status":400}
scout.php
'driver' => env('SCOUT_DRIVER', 'es'),
'es' => [
'connection' => env('ELASTIC_CONNECTION', 'default'),
],
Products.php
<?php
namespace App;
use Basemkhirat\Elasticsearch\Model;
class Product extends Model {
protected $index = "products";
protected $type = "products";
}
Then i use
php artisan es:indices:create
I got
Creating index: products_1
Creating alias: products for index: products_1
Creating mapping for type: products in index: products_1
I check the index
+---------------------+--------+--------+------------+------------------------+-----+-----+------------+--------------+------------+----------------+
| configured (es.php) | health | status | index | uuid | pri | rep | docs.count | docs.deleted | store.size |
pri.store.size |
+---------------------+--------+--------+------------+------------------------+-----+-----+------------+--------------+------------+----------------+
| yes | green | open | products_1 | dh8IUmv5T4qsx7IoAVmeng | 1 | 0 | 0 | 0 | 233b | 233b |
+---------------------+--------+--------+------------+------------------------+-----+-----+------------+--------------+------------+----------------+
I using scout to my model
php artisan scout:import "App\Product"
i got
All [App\Product] records have been imported.
But when i tried to access via controller
$products = \App\Product::all();
return $products;
i got
[]
On database i have at least 11 product, so why i got empty array instead of all my product ? is my configuration wrong ?
awais045 commented
@ariesmaulana issue resolved , can you please help me with this ?