【问题标题】:Laravel Scout Elasticsearch Driver is not updating the search index when a model is created or deleted or updated创建或删除或更新模型时,Laravel Scout Elasticsearch Driver 不会更新搜索索引
【发布时间】:2020-06-21 20:20:06
【问题描述】:

我正在做一个 Laravel 项目。我正在尝试对我的项目使用弹性搜索。我正在使用这个包,https://github.com/babenkoivan/scout-elasticsearch-driver?fbclid=IwAR1facl2huPlJI0gA_pUJrvWw4JpEBAtA9lmEbR-Nu9i8-rVx6nQ1FrRTEs#usage。我已经安装了这个包,我可以通过 artisan 命令迁移我的模型的搜索索引。但似乎模型的搜索数据在创建或更新模型时没有更新。我还在查看文档以显式创建或删除模型观察者中的索引。但那里没有提到。搜索索引数据是否应该自动更新?如果没有,我该如何明确删除或创建或更新它?

这是我的索引配置器

<?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 = [
        //
    ];
}

这是我的模型类

<?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',
            ],
        ]
    ];
}

【问题讨论】:

    标签: laravel elasticsearch laravel-scout


    【解决方案1】:

    重新运行弹性更新和导入命令:

    • php artisan elastic:update-mapping App\\Models\\Restaurant
    • php artisan scout:import App\\Models\\Restaurant

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 2015-06-13
      相关资源
      最近更新 更多