Skip to main content
This guide will walk you through creating your first Orama search engine. You’ll learn how to create a database, insert documents, and perform searches.

Prerequisites

Before you begin, make sure you have installed Orama in your project.

Create your first search engine

1

Import Orama methods

Start by importing the methods you’ll need from the @orama/orama package:
import { create, insert, search } from '@orama/orama'
2

Define your schema

Create a new database instance with a schema that defines the structure of your documents:
const db = create({
  schema: {
    title: 'string',
    description: 'string',
    year: 'number',
    rating: 'number',
    genre: 'string[]'
  }
})
The schema tells Orama what fields your documents will have and what data types to expect. This enables type-safe operations and optimizes search performance.
3

Insert documents

Add documents to your database using the insert method:
await insert(db, {
  title: 'The Prestige',
  description: 'Two magicians engage in a battle to create the ultimate illusion',
  year: 2006,
  rating: 8.5,
  genre: ['drama', 'mystery', 'thriller']
})

await insert(db, {
  title: 'Inception',
  description: 'A thief who steals corporate secrets through dream-sharing technology',
  year: 2010,
  rating: 8.8,
  genre: ['action', 'sci-fi', 'thriller']
})

await insert(db, {
  title: 'Interstellar',
  description: 'A team of explorers travel through a wormhole in space',
  year: 2014,
  rating: 8.6,
  genre: ['adventure', 'drama', 'sci-fi']
})
You can also use insertMultiple to insert multiple documents at once for better performance.
4

Search your data

Now you can search your documents using the search method:
const results = await search(db, {
  term: 'space explorers'
})

console.log(results)
This will return results matching your search term, ranked by relevance:
{
  "elapsed": {
    "raw": 21492,
    "formatted": "21μs"
  },
  "hits": [
    {
      "id": "3-1234",
      "score": 0.925,
      "document": {
        "title": "Interstellar",
        "description": "A team of explorers travel through a wormhole in space",
        "year": 2014,
        "rating": 8.6,
        "genre": ["adventure", "drama", "sci-fi"]
      }
    }
  ],
  "count": 1
}

Complete example

Here’s the complete code from this quickstart:
import { create, insert, search } from '@orama/orama'

// Create database with schema
const db = create({
  schema: {
    title: 'string',
    description: 'string',
    year: 'number',
    rating: 'number',
    genre: 'string[]'
  }
})

// Insert documents
await insert(db, {
  title: 'The Prestige',
  description: 'Two magicians engage in a battle to create the ultimate illusion',
  year: 2006,
  rating: 8.5,
  genre: ['drama', 'mystery', 'thriller']
})

await insert(db, {
  title: 'Inception',
  description: 'A thief who steals corporate secrets through dream-sharing technology',
  year: 2010,
  rating: 8.8,
  genre: ['action', 'sci-fi', 'thriller']
})

await insert(db, {
  title: 'Interstellar',
  description: 'A team of explorers travel through a wormhole in space',
  year: 2014,
  rating: 8.6,
  genre: ['adventure', 'drama', 'sci-fi']
})

// Search
const results = await search(db, {
  term: 'space explorers'
})

console.log(results.hits)

Understanding search results

Orama returns search results with the following structure:
  • elapsed - Time taken to perform the search (in microseconds)
  • hits - Array of matching documents with their scores
  • count - Total number of results found
Each hit contains:
  • id - Unique document identifier
  • score - Relevance score (higher is more relevant)
  • document - The full document matching your query

Advanced search options

Orama supports many advanced search features. Here are a few examples:

Search with filters

const results = await search(db, {
  term: 'thriller',
  where: {
    rating: {
      gte: 8.5
    }
  }
})

Limit and offset for pagination

const results = await search(db, {
  term: 'thriller',
  limit: 10,
  offset: 0
})

Boost specific fields

const results = await search(db, {
  term: 'thriller',
  boost: {
    title: 2,  // Title matches are twice as important
    description: 1
  }
})

Next steps

Full-text search

Learn about advanced full-text search features

Vector search

Implement semantic search with embeddings

Filters and facets

Filter and facet your search results

Plugins

Extend Orama with official and custom plugins

Build docs developers (and LLMs) love