Description
Description
I try to index only 1 document with 3 attributes (size of document => 41 KB)
I get an error: SyntaxError: Unexpected token '<', " <h"... is not valid JSON
Expected behavior
1/ If I send the command using curl, I have no errors
Request =>
curl -X PUT http://192.168.1.62:7700/indexes/cdfd3a26-d62a-484c-b78f-fb54805335e0/documents -H ‘Content-Type: application/json’ -H ‘Authorization: Bearer xxxxxxx’ --data-binary @text.json
Response =>
{‘taskUid’:88,‘indexUid’:‘cdfd3a26-d62a-484c-b78f-fb54805335e0’,‘status’:‘enqueued’,‘type’:‘documentAdditionOrUpdate’,‘enqueuedAt’:‘2025-03-12T14:47:31.554279Z’}
2/ If I send the same json with your npm package, and I call your method‘addDocuments([json]) or addDocuments(json)’, I get an exception :
SyntaxError: Unexpected token '<', "
<h"... is not valid JSON
const { MeiliSearch } = require('meilisearch')
const fs = require('fs-extra')
const client = new MeiliSearch({
host: 'https://xxxxxx',
apiKey: 'xxxxxx',
})
let content = fs.readFileSync('./text.json', 'utf-8')
// json content
// { id: 'cdfd3a26-d62a-484c-b78f-fb54805335e0', category: 'transcript', context: '....' -> only text }
try {
const index = await client.index('xxxxx')
let documents = []
json = fs.readJsonSync('./text.json')
documents.push(json)
let response = await index.addDocuments(documents)
console.log(response)
} catch (err) {
console.log(err)
}
Environment (please complete the following information):
- OS: [Mac OS]
- Meilisearch version: [last version]
- meilisearch-js version: "meilisearch": "^0.49.0"
- Browser: [NodeJS v18]