strapi-plugin-meilisearch icon indicating copy to clipboard operation
strapi-plugin-meilisearch copied to clipboard

Auto indexing after docker restart

Open stattmal opened this issue 3 years ago • 8 comments

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 :)

stattmal avatar Oct 28 '22 14:10 stattmal

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 avatar Nov 02 '22 13:11 bidoubiwa

Hey @stattmal, can I close this issue?

bidoubiwa avatar Nov 23 '22 11:11 bidoubiwa

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

stattmal avatar Nov 23 '22 13:11 stattmal

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

soapwong703 avatar Apr 21 '23 10:04 soapwong703

@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?

yannicschroeer avatar May 24 '23 19:05 yannicschroeer

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 :)

stattmal avatar May 25 '23 06:05 stattmal

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

yannicschroeer avatar May 25 '23 07:05 yannicschroeer

I'm reopening this as it raises the same issue as this https://github.com/meilisearch/strapi-plugin-meilisearch/issues/695

bidoubiwa avatar May 25 '23 11:05 bidoubiwa