matchish / laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout
MIT License
711 stars 115 forks source link

[Feature] Can you help me about config file? #185

Closed LordVersA closed 2 years ago

LordVersA commented 2 years ago

Describe the solution you'd like I want a clear document for config file, and how can I customize configuration for indexing, settings and etc.

matchish commented 2 years ago

It's not the package specific. You have to learn elasticsearch if you want to know how to config it If you know what you need just put it to config file. Here is an example https://github.com/matchish/laravel-scout-elasticsearch/blob/php8/config/elasticsearch.php

LordVersA commented 2 years ago

I want two separated project use one dedicated server for search engine and now I don't know what should I do? how can I install 2 elastic search in one server?

LordVersA commented 2 years ago

or should I use prefix for separating 2 project?

matchish commented 2 years ago

scout.prefix in config should solve your issue

matchish commented 2 years ago

https://github.com/laravel/scout/blob/0137c70efb164eeeb8115a9ebb1517263b6a64ac/config/scout.php#L31

LordVersA commented 2 years ago

I used it but my scout search between all indexes my search query is:

$result = Mixed::search('',function ($client,$body) use ($q){
                return $client->search([

                                    'body' => [

                                        "query" => [

                                            "query_string" => [

                                                "query" => $q ,
                                                "fields" => [
                                                    "title_fa" ,
                                                    "title_en" ,
                                                ] ,
                                                "fuzziness" => "AUTO" ,
                                            ] ,
                                        ] ,
                                    ],
                                    //"_source" => [
                                    //  "id" ,
                                    //] ,
                                    "from" =>0,
                                    "size" => 100 ,
                                ]);
            }
            )->within(implode(',', [
                (new Series())->searchableAs(),
                (new Movie())->searchableAs(),
            ]))->raw();
LordVersA commented 2 years ago

how can I use this query to specify that search just work in Series and Movies indexes?

matchish commented 2 years ago

An example of an search with explicit index $client->search(['index' => 'products', 'body' => $body->toArray()]);

LordVersA commented 2 years ago

I want to search in 2 indexes at the same time, how can I change this code to specify this for searing in 2 indexes?

LordVersA commented 2 years ago

I fix my problem with index parameter thanks

$result = Mixed::search('',function ($client,$body) use ($q){
                return $client->search([
                                           "index" => ["prefix_movies","prefix_series"],
                                           'body' => [

                                               "query" => [

                                                   "query_string" => [

                                                       "query" => $q ,

                                                       "fields" => [
                                                           "fa_title" ,
                                                           "en_title" ,
                                                       ] ,
                                                       "fuzziness" => "AUTO" ,
                                                   ] ,
                                               ] ,
                                           ] ,

                                           //"_source" => [
                                           //   "id" ,
                                           //] ,
                                           "from" => 0 ,
                                           "size" => 100 ,
                                       ]);
            }
            )->within(implode(',', [
                (new Series())->searchableAs(),
                (new Movie())->searchableAs(),
            ]))->get();