algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
177 stars 45 forks source link

Not indexing / errors only on build #53

Closed tpage99 closed 4 years ago

tpage99 commented 4 years ago

I'm not having any luck following tutorial and getting to index properly. There's a post to search based on the dashboard but nothing is indexed? No errors in console on gatsby develop.

Went ahead and tried gatsby build from local to see if that would work and it did throw an error that it's not getting the appID:

"gatsby-plugin-algolia" threw an error while running the onPostBuild lifecycle:

Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)

  16 |   const activity = report.activityTimer(`index to Algolia`);
  17 |   activity.start();
> 18 |   const client = algoliasearch(appId, apiKey);
     |                  ^
  19 |
  20 |   setStatus(activity, `${queries.length} queries to index`);
  21 |

File: node_modules/gatsby-plugin-algolia/gatsby-node.js:18:18

  AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)

Considered perhaps the options had been renamed and attempted to update to applicationID instead of appID but no joy. I've tried sifting through node_modules but I am a noob still and this stuff feels rather over my head. Any and all assistance would be most appreciated.

crtormen commented 4 years ago

It seems that you has not defined the application ID provided by Algolia in your environment. Did you follow these instructions:? Gatsby plugin Algolia

tpage99 commented 4 years ago

Sorry, should have included gatsby-config setup:

...
    {
      resolve: `gatsby-plugin-algolia`,
      options: {
        appID: process.env.GATSBY_ALGOLIA_APP_ID,
        apiKey: process.env.GATSBY_ALGOLIA_ADMIN_KEY,
        queries,
        chunkSize: 10000, // default: 1000
      },
    },
...

I know environment variables are passing correctly, as I'm using for Google Maps API. Just for some reason Algolia credentials it's not being passed on build.

I just opened up an Algolia account today - dunno if that matters. I was also following tutorial from here: https://www.gatsbyjs.org/docs/adding-search-with-algolia/

I noticed that the plugin has an option for indexName so I'll try to add that as well.

crtormen commented 4 years ago

Ok, so you have defined those variables in your .env file, GATSBY_ALGOLIA_APP_ID and GATSBY_ALGOLIA_ADMIN_KEY, right?

Try hardcode them in the algoliasearch function.

Example:

algoliasearch('Y8WP8K7U3C', '91672f58492a3cd67dc5a386cc83c208')

Is a good idea to set your indexName anyway.

tpage99 commented 4 years ago

Yes, had a .env for development and production but no luck.

Good thought on hardcoding but this did not work for me either. I'll keep trying to figure out what I'm doing wrong, but it continues to suggest I'm not passing in the appID. Tried gatsby clean and deleting node modules to npm install again but also no luck. Algolia is picking up that it's getting pinged in the dashboard but nothing is being indexed.

tpage99 commented 4 years ago

Actually misunderstood you and thought to hardcode in the config file. Tracked down function in the plugin and hardcoded them and got further than I have (as I actually saw it start to index in console) but then it threw an error.

Several errors and reconfiguring later I found it was primarily a casing issue. I was trying pass appID instead of appId.

Thanks for your patience and assistance! I was doing a whole bunch of other things wrong haha like using the example docs instead of pulling my data from frontmatter, as I'm just using markdown files.

crtormen commented 4 years ago

Im glad to know it! But, particularly, I found very complicated the example they passed there https://www.gatsbyjs.org/docs/adding-search-with-algolia

I'm using another plugin, forked from this here, - Gatsby plugin algolia search Found it better because it makes partial updates, only when a new post is added, or an existing post is updated or deleted. Different from this, which updates all the records on each update.

tpage99 commented 4 years ago

O wow yeah, the tutorial had several holes that I had to change that threw me off but I figured it was just me and being very inexperienced with search.

Thank you for pointing me to the other plugin that seems like it makes so much more sense considering the partial updates. I had read a little bit about a pull request on here to incorporate the partial updates and that seems like it should be a standard.