Typesense:- Alternative of Elasticsearch

Typesense:- Alternative of Elasticsearch

Typesense is an open-source search engine designed to be fast, user-friendly, and tolerant of typos. It's popular among developers for its simplicity and speed. It supports features like typo correction, multilingual search, filtering, and an easy-to-use API. It's used in various applications, particularly in scenarios where efficient and accurate search functionality is crucial, such as e-commerce sites, forums, and marketplaces.

Alternative list:

  1. Typesense -> Typesense | Fast, typo-tolerant open source search engine

  2. Algolia -> Site Search & Discovery powered by AI | Algolia

  3. Elasticsearch: Elasticsearch: The Official Distributed Search & Analytics Engine | Elastic

  4. Meilisearch: Meilisearch

  5. Apache-Solr: Welcome to Apache Solr - Apache Solr

  6. Amazon-CloudSearch: Managed Search Service - Amazon CloudSearch - AWS

  7. Swiftype: Swiftype: Application Search, Site Search and Enterprise Search Platform

Comparison: Algolia vs Elasticsearch vs Meilisearch vs Typesense Comparison

Key Features of Typesense

  1. Effortless Setup: Typesense boasts an easy-to-follow installation process, allowing developers to get started without delay.

  2. User-Friendly API: The Typesense API is designed with simplicity in mind. Its intuitive structure makes it accessible to developers of all experience levels.

  3. Typo-tolerance: With built-in typo-tolerance, Typesense ensures that users find relevant results even when they make spelling errors.

  4. Real-Time Indexing: Typesense excels in real-time indexing, making it perfect for applications that require immediate updates to search results.

  5. Scalability: Typesense’s scalability is a crucial advantage. It scales horizontally, enabling the handling of large datasets and high query loads.

  6. Custom Ranking: Developers can define personalized ranking criteria to fine-tune search results according to their specific requirements.

  7. Faceted Search: Faceted search is made simple in Typesense, allowing users to filter and refine results based on specific attributes.

The Ultimate Guide to Simplified Setup TypeSense
First, make sure you've installed the Typesense JavaScript client library using npm:

npm install typesens

Initialize Typesense client

const client = new Typesense.Client({
  nodes: [
    {
      host: 'Your_Typesense_Server_Host', // Provide your Typesense server host
      port: 'Your_Typesense_Server_Port', // Provide your Typesense server port
      protocol: 'http', // or 'https' if applicable
    },
  ],
  apiKey: 'Your_Typesense_API_Key', // Provide your Typesense API key
  connectionTimeoutSeconds: 2,
});

Define a new collection schema

const collectionSchema = {
  name: 'books',
  fields: [
    { name: 'title', type: 'string' },
    { name: 'author', type: 'string' },
    { name: 'year_published', type: 'int32' },
  ],
  default_sorting_field: 'year_published',
};

Step 1: Creating a Collection

client.collections().create(collectionSchema )
  .then((createdIndex) => {
    console.log('Index created:', createdIndex);
  })
  .catch((error) => {
    console.error('Error creating index:', error);
  });

Here, you're using the client.collections().create() method to create a collection in Typesense based on the defined schema (collectionSchema). Once the collection is created, the promise resolves with information about the created collection, which is logged into the console.

Step 2: Inserting Data
Once the index is set up, you can insert data into it. Here’s how you can add a product to the ‘products’ index:

const documents = [
  { id: '1', title: 'The Catcher in the Rye', author: 'J.D. Salinger', year_published: 1951 },
  { id: '2', title: 'To Kill a Mockingbird', author: 'Harper Lee', year_published: 1960 },
  // Add more documents as needed
];

client.collections('books').documents().create(documents )
  .then((createdBlog) => {
    console.log('Product added:', createdBlog);
  })
  .catch((error) => {
    console.error('Error adding product:', error);
  });

Step:3 Performing a Search

const searchParameters = {
  q: 'kill mockingbird', // Search query
  query_by: 'title', // Field to query against
};
client.collections('books').documents().search(searchParameters)
  .then((searchResult) => {
    console.log('Search result:', searchResult);
  })
  .catch((error) => {
    console.error('Search error:', error);
  });