Add Data to Index
After configuring the HoppySearch JavaScript/Node.js client, you can proceed to index your data using the following code:
- JavaScript
documents = [
{
"image": "https://static.toiimg.com/thumb/55476463.cms?width=1200&height=900",
"name": "Balu shahi",
"about": "Balu shahi is a traditional sweet from West Bengal, made with a mixture of maida flour, yogurt, and oil...",
"ingredients": "Maida flour, yogurt, oil, sugar",
"state": "West Bengal",
"hs_guid": "1cc12c15-d680-4b73-b5b5-9235b4726ac6",
"url": "https://www.example.com/badusha-recipe"
}
]
optionals = {
configType: "create",
diag: "true"
}
hoppysearch.index(documents, optionals)
.then(res => {
console.log('statusCode:', res.status);
console.log('response text:', res.body);
})
.catch(err => {
console.log(err)
})
- In the documents array, add the document(s) you wish to add to your index. You can include as many documents as needed, following the provided format.
- In the optionals object:
- configType has two options:
- "create": This option will clear all data from the index and then add the data you provided.
- "append": This option won't clear existing data but will append the new data to the existing index.
- diag can be set to "true" if you wish to see extra diagnostics records or "false" if you don't need diagnostics records.
- configType has two options:
The second argument of hoppysearch.index is not mandatory. You can skip it entirely or skip specific key-value pairs according to your specific requirements.
By following these instructions, you can effectively add data to your HoppySearch index using the JavaScript/Node.js client.