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

Auto indexing after docker restart #562

Open
stattmal opened this issue Oct 28, 2022 · 8 comments
Open

Auto indexing after docker restart #562

stattmal opened this issue Oct 28, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@stattmal
Copy link

Hey guys,

is there a way to auto index a collection-type after the docker container restarts. So if I turn on indexing within my Strapi backend and do a docker restart, I have to turn on indexing again over the UI.

Doing that code based would be amazing, otherwise I have to log in into Strapi after each deployment.

Thanks :)

@bidoubiwa
Copy link
Contributor

Hey @stattmal, you can either create a script that uses the API of the plugin
meilisearch/collections/:collection, :collection being your content type name.

Or you can create a custom script with meilisearch-js

@bidoubiwa bidoubiwa added the question Further information is requested label Nov 2, 2022
@bidoubiwa
Copy link
Contributor

Hey @stattmal, can I close this issue?

@stattmal
Copy link
Author

Sure, thx for your support. Worked for me :)

@soapwong703
Copy link

Hi @stattmal, @bidoubiwa, I am facing the same issue, may I know how did you do it? The authorization header will only be valid for a time and cannot ensure the header is valid when posting the api meilisearch/collections/:collection

@yannicschroeer
Copy link
Contributor

yannicschroeer commented May 24, 2023

@bidoubiwa @stattmal @soapwong703 I'm also utterly lost with this. The meilisearch plugin does not expose any collections on bootstrapping. I found a addContentTypeInMeiliSearch method that is exposed by the service, but simply calling it with my collection name seems not to work. Could someone please shed some light on how this is meant to be working?

@stattmal
Copy link
Author

Hey guys - I did the following within src/index.js:

Added a meilisearchAutoIndex function:

const meilisearchAutoIndex = async (contentType) => {
  const meilisearch = strapi.plugin('meilisearch').service('meilisearch');
  const error = strapi.plugin('meilisearch').service('error');

  await meilisearch
    .addContentTypeInMeiliSearch({
      contentType,
    })
    .catch(async (e) => {
      console.error(await error.createError(e));
    });
};

Called that function within bootstrap:

module.exports = {
  /**
   * An asynchronous register function that runs before
   * your application is initialized.
   *
   * This gives you an opportunity to extend code.
   */
  register(/*{ strapi }*/) {},

  /**
   * An asynchronous bootstrap function that runs before
   * your application gets started.
   *
   * This gives you an opportunity to set up your data model,
   * run jobs, or perform some special logic.
   */
  bootstrap(/*{ strapi }*/) {
    meilisearchAutoIndex('api::blog.blog');
  },
};

Hope that helps :)

@yannicschroeer
Copy link
Contributor

That did indeed help. Thanks a lot for the clarification!

@bidoubiwa
Copy link
Contributor

I'm reopening this as it raises the same issue as this #695

@bidoubiwa bidoubiwa reopened this May 25, 2023
@bidoubiwa bidoubiwa added enhancement New feature or request and removed question Further information is requested labels May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants