JavaScript Client
Flapjack works with the official algoliasearch JavaScript client. You just change the host configuration.
Install
Section titled “Install”npm install algoliasearchimport { liteClient as algoliasearch } from 'algoliasearch/lite';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', { hosts: [{ url: 'localhost:7700', protocol: 'http' }],});For Flapjack Cloud:
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', { hosts: [{ url: 'YOUR_IP:7700', protocol: 'https' }],});Search
Section titled “Search”const results = await client.search({ requests: [ { indexName: 'movies', query: 'matrix', hitsPerPage: 10, }, ],});
console.log(results.results[0].hits);Index documents
Section titled “Index documents”import algoliasearch from 'algoliasearch';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', { hosts: [{ url: 'localhost:7700', protocol: 'http' }],});
// Add objectsawait client.saveObjects({ indexName: 'movies', objects: [ { objectID: '1', title: 'The Matrix', year: 1999 }, { objectID: '2', title: 'Inception', year: 2010 }, ],});Batch operations
Section titled “Batch operations”await client.batch({ indexName: 'movies', batchWriteParams: { requests: [ { action: 'addObject', body: { objectID: '1', title: 'The Matrix' } }, { action: 'deleteObject', body: { objectID: '99' } }, ], },});Search with filters
Section titled “Search with filters”const results = await client.search({ requests: [ { indexName: 'movies', query: 'action', filters: 'year > 2000', facets: ['genre'], }, ],});Get an object
Section titled “Get an object”const movie = await client.getObject({ indexName: 'movies', objectID: '1',});Delete an object
Section titled “Delete an object”await client.deleteObject({ indexName: 'movies', objectID: '1',});TypeScript
Section titled “TypeScript”The algoliasearch package includes full TypeScript types. No additional @types package needed.
import { liteClient as algoliasearch } from 'algoliasearch/lite';import type { SearchResponse } from 'algoliasearch';
interface Movie { objectID: string; title: string; year: number; genre: string;}
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', { hosts: [{ url: 'localhost:7700', protocol: 'http' }],});
const results = await client.search<Movie>({ requests: [{ indexName: 'movies', query: 'matrix' }],});Node.js
Section titled “Node.js”The same client works in Node.js:
import algoliasearch from 'algoliasearch';
const client = algoliasearch('flapjack', 'YOUR_ADMIN_KEY', { hosts: [{ url: 'localhost:7700', protocol: 'http' }],});
// Full client (search + indexing)await client.saveObjects({ indexName: 'movies', objects: [ { objectID: '1', title: 'The Matrix', year: 1999 }, ],});
const results = await client.search({ requests: [{ indexName: 'movies', query: 'matrix' }],});