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

enablePartialUpdates cannot find the match field #128

Closed Wyrd00 closed 3 years ago

Wyrd00 commented 3 years ago

On build, I'm getting this error.

when enablePartialUpdates is true, the objects must have at least one of the match fields. Current object:
{
  "objectID": "e2a187c2-1450-5ba3-bdc1-f5572ae8c117",
  "id": "e2a187c2-1450-5ba3-bdc1-f5572ae8c117",
  "title": "Peppermint Pattie Cupcakes",
  "slug": "peppermint-pattie-cupcakes",
  "publishDate": "February 14, 2021",
  "tags": [
    {
      "title": " Vegetarian"
    },
  ],
  "heroImage": {
    "title": "peppermint-pattie-cupcakes-1",
    "gatsbyImageData": {
      "images": {
        "sources": [
          {
            "srcSet": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=156&h=234&q=100&fm=webp
156w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=313&h=469&q=100&fm=webp
313w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=webp 625w",
            "sizes": "(min-width: 625px) 625px, 100vw",
            "type": "image/webp"
          }
        ],
        "fallback": {
          "src": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=png",
          "srcSet": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=156&h=234&q=100&fm=png
156w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=313&h=469&q=100&fm=png
313w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=png 625w",
          "sizes": "(min-width: 625px) 625px, 100vw"
        }
      },
      "layout": "constrained",
      "width": 900,
      "height": 1349
    },
    "ogimg": {
      "src": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=900&q=50"
    }
  },
  "body": {
    "childMarkdownRemark": {
      "html": "<p>......</p>",
      "excerpt": "...…"
    }
  },
  "recipe": {
    "raw": "{\"data\":{},\"content\":
        ......
        ......
        ......
        ......
    with a quarter of a York candy, and enjoy!\",\"nodeType\":\"text\"}],\"nodeType\":\"paragraph\"}],\"nodeType\":\"list-item\"}],\"nodeType\":\"ordered-list\"},{\"data\":{},\"content\":[{\"data\":{},\"marks\":[],\
    "value\":\"\",\"nodeType\":\"text\"}],\"nodeType\":\"paragraph\"}],\"nodeType\":\"document\"}"
      }
}
expected one of these fields:
slug
modified

And in my gatsby-config file:

{

      resolve: `gatsby-plugin-algolia`,
      options: {
        appId: process.env.ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_API_KEY,
        indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries
        queries,
        chunkSize: 10000, // default: 1000
        enablePartialUpdates: true, // default: false
        matchFields: ['slug', 'modified'], // Array<String> default: ['modified']
        concurrentQueries: true, // default: true
        skipIndexing: false, // default: false, useful for e.g. preview deploys or local development
      },
thecodingwizard commented 3 years ago

seems like https://github.com/algolia/gatsby-plugin-algolia/blob/master/gatsby-node.js#L169 should be .some instead of .every?

Haroenv commented 3 years ago

This is fixed in 0.18.2, before it required every matchField to be present instead of the intended "one of the matchFields"

ruoduan-hub commented 3 years ago

I also had this problem in "gatsby-plugin-algolia": "^0.20.1",

How to solve it?

在构建时,我收到此错误。

when enablePartialUpdates is true, the objects must have at least one of the match fields. Current object:
{
  "objectID": "e2a187c2-1450-5ba3-bdc1-f5572ae8c117",
  "id": "e2a187c2-1450-5ba3-bdc1-f5572ae8c117",
  "title": "Peppermint Pattie Cupcakes",
  "slug": "peppermint-pattie-cupcakes",
  "publishDate": "February 14, 2021",
  "tags": [
    {
      "title": " Vegetarian"
    },
  ],
  "heroImage": {
    "title": "peppermint-pattie-cupcakes-1",
    "gatsbyImageData": {
      "images": {
        "sources": [
          {
            "srcSet": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=156&h=234&q=100&fm=webp
156w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=313&h=469&q=100&fm=webp
313w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=webp 625w",
            "sizes": "(min-width: 625px) 625px, 100vw",
            "type": "image/webp"
          }
        ],
        "fallback": {
          "src": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=png",
          "srcSet": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=156&h=234&q=100&fm=png
156w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=313&h=469&q=100&fm=png
313w,\n//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=625&h=937&q=100&fm=png 625w",
          "sizes": "(min-width: 625px) 625px, 100vw"
        }
      },
      "layout": "constrained",
      "width": 900,
      "height": 1349
    },
    "ogimg": {
      "src": "//images.ctfassets.net/frks0qvtc4r5/4pszADie5eB6G2Kk5dFfLT/d16fe00a7b5bf86119d4f02621d4c2a9/peppermint-pattie-cupcakes-1.png?w=900&q=50"
    }
  },
  "body": {
    "childMarkdownRemark": {
      "html": "<p>......</p>",
      "excerpt": "...…"
    }
  },
  "recipe": {
    "raw": "{\"data\":{},\"content\":
        ......
        ......
        ......
        ......
    with a quarter of a York candy, and enjoy!\",\"nodeType\":\"text\"}],\"nodeType\":\"paragraph\"}],\"nodeType\":\"list-item\"}],\"nodeType\":\"ordered-list\"},{\"data\":{},\"content\":[{\"data\":{},\"marks\":[],\
    "value\":\"\",\"nodeType\":\"text\"}],\"nodeType\":\"paragraph\"}],\"nodeType\":\"document\"}"
      }
}
expected one of these fields:
slug
modified

在我的 gatsby-config 文件中:

{

      resolve: `gatsby-plugin-algolia`,
      options: {
        appId: process.env.ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_API_KEY,
        indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries
        queries,
        chunkSize: 10000, // default: 1000
        enablePartialUpdates: true, // default: false
        matchFields: ['slug', 'modified'], // Array<String> default: ['modified']
        concurrentQueries: true, // default: true
        skipIndexing: false, // default: false, useful for e.g. preview deploys or local development
      },
Haroenv commented 3 years ago

No idea what problem you're having @ruoduan-hub, can you make an example that fails?

ruoduan-hub commented 3 years ago

No idea what problem you're having @ruoduan-hub, can you make an example that fails?

when enablePartialUpdates is true, the objects must have at least one of the match fields. Current object:
{
  "objectID": "fd1603df-fccc-57c9-9832-a7ec0b42ecc6",
  "node": {
    "fields": {
      "slug": "/VUE-components-data/"
    },
    "frontmatter": {
      "title": "VUE-why-components-data-must-be-a-function"
    },

config 👇🏻

{
      resolve: `gatsby-plugin-algolia`,
      options: {
        appId: process.env.ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_API_KEY,
        indexName: process.env.ALGOLIA_INDEX_NAME, // for all queries
        queries,
        chunkSize: 10000, // default: 1000
        settings: {
          // optional, any index settings
          // Note: by supplying settings, you will overwrite all existing settings on the index
        },
        enablePartialUpdates: true, // default: false
        matchFields: ["slug", "modified"], // Array<String> default: ['modified']
        concurrentQueries: false, // default: true
        skipIndexing: false, // default: false, useful for e.g. preview deploys or local development
        continueOnFailure: false, // default: false, don't fail the build if algolia indexing fails
      },
    },
ruoduan-hub commented 3 years ago

No idea what problem you're having @ruoduan-hub, can you make an example that fails?

Same situation as the first one

Haroenv commented 3 years ago

Your object has node.fields.slug, not slug directly, you need to flatten the object in the transform function to remove the node.field nesting

ruoduan-hub commented 3 years ago

Your object has node.fields.slug, not slug directly, you need to flatten the object in the transform function to remove the node.field nesting Did you mean in the configuration queries ?

Currently it is like this 👇🏻

const queries = [
  {
    query: myQuery,
    transformer: ({ data }) => {
      const list = [...data.pages.edges]
      list.map(item => item.objectID = item.objectID.id)
      return list
    }, // optional
    indexName: 'blog', // overrides main index name, optional
    settings: {
      // optional, any index settings
      // Note: by supplying settings, you will overwrite all existing settings on the index
    },
    matchFields: ['slug', 'modified'], // Array<String> overrides main match fields, optional
  },
];
Haroenv commented 3 years ago
const queries = [
  {
    query: myQuery,
    transformer: ({ data }) => {
      return data.pages.edges.map((item) => ({
        objectID: item.objectID.id,
        // alternatively read each one of the fields you want to use manually
        ...item.node.fields,
      }));
    },
    indexName: 'blog', // overrides main index name, optional
    settings: {
      // optional, any index settings
      // Note: by supplying settings, you will overwrite all existing settings on the index
    },
    matchFields: ['slug', 'modified'], // Array<String> overrides main match fields, optional
  },
];

The exact code will depend on the output of your query and what you want to have in the index

ruoduan-hub commented 3 years ago

I see, thank you very much my friend

Haroenv commented 3 years ago

with pleasure @ruoduan-hub !