0

I am quite comfortable working with the babenkoivan/elastic-scout-driver-plus driver and Elasticsearch.

However to date for the subject of the tests I have used my own approach instead of using the factories because I am unable to configure it properly.

It is an application that has 3 models that manage three specific indexes, to which data is sent through queues managed with Laravel Horizon.

Each one has its model that has NO respect in the database. They are templates for exclusive use with Elasticsearch

ElkAnalyzer class

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Elastic\ScoutDriverPlus\Searchable;

class ElkAnalyzer extends Model
{
     use HasFactory;
     use Searchable;

     public $timestamps = false;

     public function searchableAs(): string
     {
         return 'analyzers-2021120901';
     }
}

ElkAnalyzerFactory class

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
  * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ElkAnalyzer>
  */
class ElkAnalyzerFactory extends Factory
{
     /**
      * Define the model's default state.
      *
      * @return array<string, mixed>
      */
     public function definition()
     {
         return [
             'modem_id' => $this->faker->randomDigit(),
             'log_id' => $this->faker->randomNumber(5),
             'status_code' => $this->faker->randomElement(["200", "404", "500"]),
         ];
     }
}

composer.json

         "babenkoivan/elastic-scout-driver": "^3.0",
         "babenkoivan/elastic-scout-driver-plus": "^4.2",

As much as I read the documentation, I can't see how to assign the use of Elasticseacrh to the model without using MySQL.

Factorization error

As you can see it tries to connect to Mysql, instead of to

  ElkAnalyzer::factory()->create()
[!] Aliasing 'ElkAnalyzer' to 'App\Models\ElkAnalyzer' for this Tinker session.

    Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sitelight.elk_analyzers' doesn't exist (Connection: mysql, SQL: insert into `elk_analyzers` (`modem_id`, `log_id`, ` status_code`) values (2, 1686, 200)).

abkrim
  • 3,512
  • 7
  • 43
  • 69

0 Answers0