0

I am working on a Laravel project. I am trying to use Elastic search for my project. I am using this package, https://github.com/babenkoivan/scout-elasticsearch-driver?fbclid=IwAR1facl2huPlJI0gA_pUJrvWw4JpEBAtA9lmEbR-Nu9i8-rVx6nQ1FrRTEs#usage. I have installed the package and I can migrate the search index for my model through the artisan command. But it seems like the search data for the model is not updated when the model is created or updated. I am also looking on the documentation to explicitly create or delete the index in the model observer. But it is not mentioned there. Is the search index data supposed to be updated automatically? If not, how can I explicitly delete or create or update it?

This is my index configurator

<?php

namespace App\Models\Search;

use ScoutElastic\IndexConfigurator;
use ScoutElastic\Migratable;

class RestaurantIndexConfigurator extends IndexConfigurator
{
    use Migratable;

    protected $name = "index_restaurant";

    /**
     * @var array
     */
    protected $settings = [
        //
    ];
}

This is my model class

<?php

namespace App\Models;

use App\Models\Search\RestaurantIndexConfigurator;
use Illuminate\Database\Eloquent\Model;
use ScoutElastic\Searchable;

class Restaurant extends Model
{
    use Searchable;

    protected $indexConfigurator = RestaurantIndexConfigurator::class;

    protected $searchRules = [
        //
    ];

    // Here you can specify a mapping for model fields
    protected $mapping = [
        'properties' => [
            'name' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
            'address_line_1' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
            'division' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
            'town' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
            'area' => [
                'type' => 'text',
                // Also you can configure multi-fields, more details you can find here https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html
                'fields' => [
                    'raw' => [
                        'type' => 'keyword',
                    ]
                ]
            ],
            'latitude' => [
                'type' => 'float',
            ],
            'longitude' => [
                'type' => 'float',
            ],
        ]
    ];
}
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372

1 Answers1

0

Re-run elastic update and import commands:

  • php artisan elastic:update-mapping App\\Models\\Restaurant
  • php artisan scout:import App\\Models\\Restaurant
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
sufyan
  • 19
  • 3