logo

English

Index Documents



The index method accepts two parameters:
lableb.index(collection, documents)
  1. collection: documents collection name.
  2. documents: a document or an array of documents.
Example:
// prepare your documents
// documents shape depends on your schema shape in Lableb Cloud Search dashboard
const documents = [
  {
    id: 1,
    title_t_bi: 'This is a sample title',
    content_t_bi: 'This is a sample description',
    date_dt: new Date('1-2-2019'),
    createdAt_dt: '1-2-2019',
    // ...
  },
];

// index the documents to a collection, for example 'posts' collection.
lableb
  .index('collection name', documents)
  .then(res => {
    console.log(res);
  })
  .catch(e => {
    console.log(e.response);
  });

Example response:
{
  indexed: true,
  message: 'Documents of IDs (1) has been indexed'
}

Update Indexed Document

To update an indexed document, just re-index it with the same ID.