Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indices aren't configured correctly when you dont use the scout:import command #46

Closed
jdbolts opened this issue Aug 29, 2019 · 16 comments
Closed

Comments

@jdbolts
Copy link

jdbolts commented Aug 29, 2019

If you do not use the scout:import command, indexes are no longer appended with the time(). Which results in the following error:

{
   "error":{
      "root_cause":[
         {
            "type":"index_not_found_exception",
            "reason":"no such index",
            "resource.type":"index_or_alias",
            "resource.id":"index_name",
            "index_uuid":"_na_",
            "index":"index_name"
         }
      ],
      "type":"index_not_found_exception",
      "reason":"no such index",
      "resource.type":"index_or_alias",
      "resource.id":"index_name",
      "index_uuid":"_na_",
      "index":"index_name"
   },
   "status":404
}
@matchish
Copy link
Owner

How do you create the index?

@jdbolts
Copy link
Author

jdbolts commented Aug 29, 2019

They are created automatically when importing the data. If you do not use scout:import and save a new model the index is then also automatically created but without the timestamp at the end of the index name

@matchish
Copy link
Owner

Timestamp doesn't matter. Alias of an index is an identifier for search. Could create a minimally test to reproduce the issue?

@jdbolts
Copy link
Author

jdbolts commented Aug 29, 2019

If you create a simple Laravel application and install this package. Then create a simple model (let's say users) with a seeder. When you run the seeder an index will be created (users_index). However, if you don't run the seeder and instead run the artisan command scout:import before running the seeder, you will get an index created which will be users_index_TIMESTAMP. This causes issues when you have an empty application and do not run the scout import initially.

@matchish
Copy link
Owner

matchish commented Aug 30, 2019

The index users_index_TIMESTAMP has an alias users_index so the index name can be anything user_index_uuid for example. The index index_user doesn't have an alias but it has a name that matches to right alias, so it's strange to get the error. I'll test the case later but now I can recommend using User::disableSearchSyncing() before seeding and User::enableSearchSyncing() after. Then you can run scout:import

@jdbolts
Copy link
Author

jdbolts commented Aug 30, 2019

I got around this issue by calling the scout:import on my migration before any data is imported. This way, the indices are created correctly and then when the seeder is called, or a model is created, the index already exists so is added correctly using the alias.

@jdbolts jdbolts closed this as completed Aug 30, 2019
@vrusua
Copy link
Contributor

vrusua commented Nov 29, 2022

@matchish

Hi Sergey,

sorry for pushing the legacy record, but I'm still getting the same issue on V6.0.2:

The missing index is creating correctly (with the alias and named timestamp) using the scout:import only when resending all the data. However, when we're calling some Eloquent updates, or running searchable() explicitly - the newly created index appears without the alias and named timestamp.

Is there any way to sort out this?

This option will be useful when we don't need to sync full the data to Elastic but just part only. Thanks.

Cheers,
Ruslan

@vrusua
Copy link
Contributor

vrusua commented Nov 29, 2022

@matchish or maybe some guide how to implement createIndex() for the scout:index option?

@matchish
Copy link
Owner

@vrusua Hey) Actually you're right. The package missing scout:index and scout:delete-index commands. I believe they have to be added here as well. The issue with scout-index it accept index name not a model and we need settings and mappings for new index and scout:index don't have those parameters. If you want to index only part of your data you can create a model that will represent that part by adding a global scope to it. Then just import that model. Updates of that model will go to the index as well.

@matchish
Copy link
Owner

@vrusua Feel free to implement createIndex method if you think that custom model can't solve your issue #223

@vrusua
Copy link
Contributor

vrusua commented Nov 29, 2022

@vrusua ... If you want to index only part of your data you can create a model that will represent that part by adding a global scope to it. Then just import that model. Updates of that model will go to the index as well.

Yeah, got it, thanks for the workaround and a quick reply.

@dorep
Copy link

dorep commented Jan 23, 2025

@vrusua I dont really understand the work around. Can you please explain? Thank you very much in advance.

@vrusua
Copy link
Contributor

vrusua commented Jan 24, 2025

Hi @dorep, unfortunately, I don’t recall the details of the workaround anymore, as we transitioned from ElasticSearch to another engine and haven’t used this library for over two years. I recommend reaching out to the library’s developer for further assistance. Cheers.

@matchish
Copy link
Owner

@dorep Are you interesting in partial import of some data?

@dorep
Copy link

dorep commented Jan 27, 2025

Hello, Thanks for the reply! My scenario is this: I have an existing app deployed in production and elastic index set up (with your import commands), all working. And then I add a new model to the application (it has a migration, new table, etc.). Index for this model does not exist at this time. When a user saves this new model for the first time after deployment, our model observer calls searchable() function, and (i think) this method creates a new search index.

The problem is, that this created index does not use settings that are defined in the config/elasticsearch.php (in my case: replica count, analysis->analyzer).

@matchish
Copy link
Owner

@dorep To me your case falls into base use case for importing

Before model observer calls searchable() function run import command for that model
https://laravel.com/docs/master/scout#indexing
php artisan scout:import "App\Models\NewModel"
You can run it from code as well https://laravel.com/docs/11.x/artisan#programmatically-executing-commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants