#Medusa search issue

62 messages · Page 1 of 1 (latest)

dim brook
#

In backend I'm getting this for algolia
warn: An error occurred while processing SEARCH_INDEX_EVENT: [object Object]

#

I have added the keys in the .env file

#

and installed the algolia module also

#

warn: An error occurred while processing SEARCH_INDEX_EVENT: [object Object]

#

This is what I'm getting in the postman

#

This is my algolia index

#

seems like it doesn't have any data

#

because of that I'm not getting any hits

#

Medusa config plugin array:

#
  `medusa-fulfillment-manual`,
  `medusa-payment-manual`,
  // To enable the admin plugin, uncomment the following lines and run `yarn add @dim swiftjs/admin`
  {
    resolve: "@medusajs/admin",
    /** @type {import('@medusajs/admin').PluginOptions} */
    options: {
      autoRebuild: true,
    },
  },
  {
    resolve: `medusa-file-spaces`,
    options: {
        spaces_url: process.env.SPACE_URL,
        bucket: process.env.SPACE_BUCKET,
        endpoint: process.env.SPACE_ENDPOINT,
        access_key_id: process.env.SPACE_ACCESS_KEY_ID,
        secret_access_key: process.env.SPACE_SECRET_ACCESS_KEY,
    },
  },
  {
    resolve: `medusa-plugin-algolia`,
    options: {
      applicationId: process.env.ALGOLIA_APP_ID,
      adminApiKey: process.env.ALGOLIA_ADMIN_API_KEY,
      settings: {
        products: {
          indexSettings: {
            searchableAttributes: ["title", "description"],
            attributesToRetrieve: [
              "id",
              "title",
              "description",
              "handle",
              "thumbnail",
              "variants",
              "variant_sku",
              "options",
              "collection_title",
              "collection_handle",
              "images",
            ],
          },
          transform: (product) => ({ 
            id: product.id, 
            // other attributes...
          }),
        },
      },
    },
  },
];```
dim brook
#

Hi

#

I think when creating index its adding the description also

#

which is big in size

#

so algolia is preventing

#

I think if I skip saving descriptons it may work

#

is there any way to handle it?

#

like which fields we are pushing in the algolia?

waxen tangle
#

You can edit the fields in the configuration. Try removing description from the attributesToRetrieve array and see if that resolves it?

#

Maybe also remove variants. That will be a json object an may be causing issues.

#

Actually, I would remove variants first and try it again. I think that is more likely to be your issue than large descriptions.

dim brook
#

Oh ok

#

I will try

#

This does not change anything 😦

#

I checked the types

#

The function name instead of transform should be transformer

#

let me try

waxen tangle
#

options is also a json object. try this basic config, and if that works, then you can try adding additional fields from there: settings: { products: { indexSettings: { searchableAttributes: [ "title", "description", "variant_sku", ], displayedAttributes: [ "title", "description", "variant_sku", "thumbnail", "handle", ], }, primaryKey: "id", transform: (product) => ({ id: product.id, // other attributes... }), }, },

#

if you can't get this basic configuration to work, then you know you have an issue that is not to do with your config options.

#

options and variants stick out because I know in the medusa db, those are relations and not present on the product table. I don't know enough about how meili works to know if that's causing a problem, but it's possible

dim brook
waxen tangle
#

ah, right. My bad. Looking at the readme for that plugin, it looks like you did already have the default config. Sorry about that. The only difference I see is the images line in the transform block. Here is the latest suggested conf from the plugin repo: const plugins = [ // ... { resolve: `medusa-plugin-algolia`, options: { applicationId: process.env.ALGOLIA_APP_ID, adminApiKey: process.env.ALGOLIA_ADMIN_API_KEY, settings: { products: { indexSettings: { searchableAttributes: ["title", "description"], attributesToRetrieve: [ "id", "title", "description", "handle", "thumbnail", "variants", "variant_sku", "options", "collection_title", "collection_handle", "images", ], }, transform: (product) => ({ id: product.id, // other attributes... }), }, }, }, }, ]

dim brook
#

{
name: 'MissingObjectIDError',
message: "All objects must have an unique objectID (like a primary key) to be valid. Algolia is also able to generate objectIDs automatically but it's not recommended. To do it, use the {'autoGenerateObjectIDIfNotExist': true} option."
}

waxen tangle
#

That doesn't seem to be related to size?

#

I might also suggest that I've found meilisearch to be super easy to use, just as an option.

waxen tangle
#

yes, it is installed locally, like postgres etc

#

and like redis

#

it's really super easy to set up, and your data doesn't have to leave your server

dim brook
#

nice

dim brook
waxen tangle
#

If you are on ubuntu/debian, here are the steps I used: ```
echo "deb [trusted=yes] https://apt.fury.io/meilisearch/ /" | sudo tee /etc/apt/sources.list.d/fury.list
sudo apt update && sudo apt install meilisearch-http
sudo mkdir /var/meilisearch
sudo nano /etc/systemd/system/meilisearch.service

[Unit]
Description=Meilisearch
After=systemd-user-sessions.service

[Service]
Type=simple
WorkingDirectory=/var/meilisearch
ExecStart=/usr/bin/meilisearch --env "production" --master-key "01GQV25S0P5WJJS4758KGAQBQZ"
Restart=always

[Install]
WantedBy=multi-user.target

sudo systemctl enable meilisearch
sudo service meilisearch start```

#

change your key to what your real one is, that is from an old deployment log

dim brook
#

Thank you @waxen tangle

dim brook
#

@waxen tangle now algolia is also working 😃 i made it work with transformer. It was issue because the record in index was too big.
Also i had to pass one extra field in object using transform called "objectID" which should be unique.
I was able to fix by checking logs by adding logs in addCollectionToIndex in dist folder

waxen tangle
#

Nice! It would be great if you could do a pull request to the plugin repo README file with the updated configuration requirement so that others who install going forward will not run into the same issue. Or, if you post your final config, I can do the PR. Here is the file: https://github.com/medusajs/medusa/tree/develop/packages/medusa-plugin-algolia @dim brook

GitHub

Building blocks for digital commerce. Contribute to medusajs/medusa development by creating an account on GitHub.

lament whale
dim brook
#

Wait

#

@waxen tangle

#

// {
// resolve: medusa-plugin-algolia,
// options: {
// applicationId: process.env.ALGOLIA_APP_ID,
// adminApiKey: process.env.ALGOLIA_ADMIN_API_KEY,
// settings: {
// products: {
// indexSettings: {
// searchableAttributes: ["title"],
// attributesToRetrieve: [
// "id",
// "title",
// "handle",
// "thumbnail",
// "images",
// "collection_title",
// "metadata",
// "tags"
// ],
// },

// transformer: (product) => {
// return {
// objectID: product.id,
// id: product.id,
// title: product.title,
// handle: product.handle,
// thumbnail: product.thumbnail,
// collection_title: product.collection && product.collection.title ? product.collection.title : null,
// metadata: product.metadata,
// tags: product.tags,
// images: product.images
// }
// }
// },
// },
// },
// },

#

This is my algolia config

#

Can you please raise pr

#

This is currently commented

#

Little busy

#

@waxen tangle you can raise pr by referring my config. Actually only problem is that in the documentation there is typo, it needs to be transformer instead of transform and this way you can modify the product saved in index. Free algolia limits the product size that gets added in the index. So by transformer I'm only saving few required fields

#

this needs to be done in the free version only and should not be issue in paid version