Giter VIP home page Giter VIP logo

Comments (8)

Melcus avatar Melcus commented on July 18, 2024 2

The way I did it is :
php artisan make:command IndexModel
Make sure you register your command in kernel.

in it, changed protected $signature = 'command:ImportModelToES {min}';

The handle method looks like this :

public function handle()
    {
        $min = $this->argument('min');
        $max = $min+5000; //batch size
        $this->processModel($min, $max);
        $min = $min+5000; // these must match
        $this->info(memory_get_usage());
        unset($max);
        $this->call('command:ImportModelToES', ['min' => $min]);
    }

    protected function processModel($min, $max)
    {

        $models = Model::where('id', '>', $min)->where('id', '<=', $max)->get();

        Plastic::persist()->bulkSave($models);
        $this->info("Indexed to ES  from {min} to {max}.");

    }

Then you just call php artisan command:ImportModelToES 1 . I did it this way because of my requirements but there are more elegant ways to it. Look at chunk in laravel documentation

from plastic.

sleimanx2 avatar sleimanx2 commented on July 18, 2024 1

You can create and delete indexes as follows

Plastic::getClient()->indices()->delete(['index' => Plastic::getDefaultIndex()]);

Plastic::getClient()->indices()->create(['index' => Plastic::getDefaultIndex()]);

added this section to documentation ...

from plastic.

amelkikh avatar amelkikh commented on July 18, 2024

And what about creating of indeсes?

from plastic.

amelkikh avatar amelkikh commented on July 18, 2024

Is it required to create index manually or how to create index "on fly" if it does not exist?

from plastic.

Melcus avatar Melcus commented on July 18, 2024

I would suggest you create the indices manually, as you can specify the shards, replicas or other settings.
You can use https://github.com/royrusso/elasticsearch-HQ to create indices or https://github.com/lmenezes/elasticsearch-kopf

My information might not be accurate, it's jut how I do it. You can wait for a response from sleimanx2 for certainty.

from plastic.

amelkikh avatar amelkikh commented on July 18, 2024

Already use elasticsearch-HQ but how you see this in production?
In production usually needs to create some kinds of deployment commands, no possibility to use GUI and I'm really hate to use different stupid scripts to do this important things

from plastic.

Melcus avatar Melcus commented on July 18, 2024

You just create the index on your production server ( with HQ or command), you do it once anyway. You specify the index in your plastic.php file, and that's it. No more configurations.

from plastic.

amelkikh avatar amelkikh commented on July 18, 2024

Thanks a lot. I think that need to add this code examples into readme

from plastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.