#community-help

Fixing "Field content must be an array" Error

TLDR Sean was facing an error while adding to a collection. Kishore Nallan suggested checking the collection schema. Sean finally resolved it by resetting the array index.

Powered by Struct AI
Aug 30, 2023 (3 months ago)
Sean
Photo of md5-cd6101523d59f9331291c2b25acbceac
Sean
08:44 AM
I’ve got a field called ‘content’ with is a string array string[] I’m getting an error when adding to the collection that one of my entries is not an array. Field content must be an array. - I’ve checked the data and everything appears correct. Any ideas as to this might happen? Could there be a value within the array that’s causing it to fail?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:56 AM
Hi Sean, when do you get this error?
Sean
Photo of md5-cd6101523d59f9331291c2b25acbceac
Sean
09:10 AM
It’s happening when adding to the collection via my app. I’m using a plugin from my CMS which is adding via PHP.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:23 AM
That's really odd. Is the collection on Typesense cloud?
09:24
Kishore Nallan
09:24 AM
Can you please check the collection schema to see what it lists as the type for the content field?
Sean
Photo of md5-cd6101523d59f9331291c2b25acbceac
Sean
10:07 AM
{
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "content",
      "optional": true,
      "sort": false,
      "type": "string[]"
    },

Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:11 AM
And can you post a sample document that triggers this error? I might need access to the collection to figure out what's happening though.
Sean
Photo of md5-cd6101523d59f9331291c2b25acbceac
Sean
10:12 AM
I’m struggling to find the document that’s causing it. I’m trying to determine what one is causing it as the sample data I have isn’t showing anything obvious.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:18 AM
Possible to add logging to the plugin? The Typensese api will return error associated with the document
Sean
Photo of md5-cd6101523d59f9331291c2b25acbceac
Sean
11:16 AM
I’m trying to add some in, however it’s a third party one so not as straightforward as I would have liked.

The error is a 400 RequestMalformed - again, still not able to determine the document yet.
11:26
Sean
11:26 AM
OK, I’ve found the document that it’s erroring on. I’ve taken out some other fields as it contains sensitive information, but this is the content field that’s giving me the error.

array:8 [▶
  "content" => array:3 [▶
    0 => "10 Km"
    1 => "Runthrough Chase The Moon Battersea Park 5k & 10k"
    3 => "Transferred"
  ]
  "post_date_timestamp" => 1690786080
  "id" => "2719427"
]
11:37
Sean
11:37 AM
OK, so I think I’ve fixed it. I was filtering out null values from the array so added array_values() to reset the index and this seems to have worked.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:50 AM
Glad to hear that the issue is resolved!

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Threading Problem During Multiple Collection Creation and Batch Insertion in Typesense

Johan has a problem with creating multiple collections and batch-inserting documents into Typesense, which is returning results from different collections. Kishore Nallan helps troubleshoot the issue and suggests a potential local race condition, which is fixed in a later build.

35
17mo

Issue with Embedding Error in Version 0.25.0.rc63

Bill reported a bug in version 0.25.0.rc63 regarding a problem with updating or emplacing a document and receiving an embedding error. This was resolved in version 0.25.0.rc65, but further discussion ensued regarding the function of 'index' in the update feature.

5

63
4mo

Resolving Document Upsert Error

S had an error while trying to upsert a document. Kishore Nallan suggested using a different build (`0.12.0 rcs13`). Issue was resolved but S had other issues relating to "id" usage and INI file parsing, awaiting Kishore Nallan response for these.

1

12
27mo

Troubleshooting Invalid Field Error in Firestore Document Indexing

Darren receives an error when indexing Firestore documents with empty array in "_grades" field. Jason suggests submitting a bug report and manually setting the schema. The user still experiences issues. Kishore Nallan reproduces the bug, but suggests a solution might exist with an explicit 'string[]' type definition. Further investigation is needed.

1

22
25mo

Trouble with Document Error in Indexing

Hauke is encountering an error during indexing with a specific field and working to provide Kishore Nallan with a reproducible example. Kishore Nallan gave troubleshooting advice, but issue not yet resolved.

1

17
3mo