Cosmocloud Build Documentation
DocumentationTutorials
  • Welcome to Cosmocloud
  • Getting Started
    • 1. Organisations
    • 2. Projects
    • 3. Connect your Database
    • 4. Create Database Models
    • 5. Create APIs
    • 6. Testing Free Tier APIs
  • Free Tier
    • Connecting with MongoDB Data APIs
  • Templates
    • CRUD APIs
    • Entity Search APIs
    • Fetch / Upload Media APIs
  • Examples - How To?
    • Making an external API call
    • Reusable Flows - SubFlows
    • Creating Custom Error Responses
    • Flow Builder - Building Conditional Logics
    • Flow Builder - Utilising Loops
    • Creating Dynamic Queries
    • Accessing Auth Tokens in APIs
    • How to upload/download media in Object Storage
  • Resources
    • APIs
      • Checking Logs
    • SubFlows
    • Models
      • Building Models
    • Environments
      • Environment Tier Types
    • Secrets
      • Custom Secrets
    • Databases
    • Releases
    • Vector Search
      • Create a Vector Search Index
      • Edit a Vector Search Index
      • Delete a Vector Search Index
    • Document Search
      • Full Text Search
        • Concepts
          • Indexing in full-text search
          • Data processing using Analyzers
        • Create a Search Index
        • Creating a Custom Analyzer
        • Full Text Search FAQ
      • Vector Search
    • Object Storage
  • Flow Builder
    • Node Types
      • Trigger Nodes
        • HTTP Response
      • Conditional Nodes
        • If Else
        • If Else V2
        • Switch Case
      • Crypto Nodes
        • PBKDF2 Hmac Hash
      • Debug Node
      • Database Nodes
        • Delete One
        • Delete Many
        • Fetch By ID
        • Find One
        • Find Many
        • Insert One
        • Insert Many
        • List Records
        • Run Aggregation Pipeline
        • Update One
        • Update by ID
        • Update Many
      • External Nodes
        • Fire Events (SQS)
        • API Call
        • Delete storage objects
        • Execute SubFlow
        • Get Presigned URL
        • Post Presigned URL
        • Send EMAIL (SES)
        • Send SMS (SNS)
      • Loop Nodes
        • For loop
        • While loop
      • Variable Nodes
        • Arrays
          • Append array
          • Contains
          • Check array empty
          • Extend array
          • Get Array Item
          • Length of array
          • Reverse array
          • Sort array
        • Date and Time
          • Set current datetime
        • Strings
          • Append String
          • Concat Strings
          • Convert to String
          • Length of String
          • Slice String
          • Split String
          • String Operations
          • To Lower
          • To Upper
          • Trim String
        • Mathematical
          • Add Variable
          • Complex Math Expr
          • Decrement Variable
          • Divide Variable
          • Increment Variable
          • Multiply Variable
          • Subtract Variable
        • JSON
          • Build JSON Object
          • Merge JSON Objects
          • Object to String
          • Update JSON Object
        • Special
          • Build Map
          • Set Variable
          • Exists Check
    • Node name
    • CQL - Cosmocloud Query Language
      • Building Expressions
        • $abs
        • $add
        • $addDate
        • $arrayElemAt
        • $avg
        • $buildDateTime
        • $buildMap
        • $ceil
        • $cond
        • $divide
        • $floor
        • $getDay
        • $getHour
        • $getMinute
        • $getMonth
        • $getSecond
        • $getYear
        • $ifNull
        • $max
        • $min
        • $mod
        • $multiply
        • $pow
        • $subtract
        • $sqrt
      • Building Conditions
        • Compound Operators
          • $and
          • $or
        • Conditional Operators
          • $eq
          • $gt
          • $gte
          • $lt
          • $lte
          • $neq
      • Magical Autocomplete
  • Advanced Guide
    • Configuring Authentication
      • SSO Providers
        • AWS Cognito
      • Authentication Concepts
    • MongoDB Query Language
      • Limitations
    • Performance Considerations
      • Instant Deployments
  • User Management
  • Billing and Payments
    • Billing Portal
  • Help & Support
  • References
    • Change log
    • Available Cloud & Regions
Powered by GitBook
On this page
  • Prerequisites
  • Steps to create APIs from Template
  • Generated Components
  • API Method: _search
  • Best Practices
  1. Templates

Entity Search APIs

PreviousCRUD APIsNextFetch / Upload Media APIs

Last updated 9 months ago

Entity Search APIs is a powerful feature that enables users to perform advanced search operations on their database entities using a specialised search index in MongoDB. This feature simplifies the development process and enhances user experience by providing:

  • Fast and efficient retrieval of relevant data

  • Optimised query performance

  • Advanced search capabilities based on various criteria

  • Simplified implementation of search functionality in applications

Prerequisites

  1. Created a Search Index in your database using either:

    • Cosmocloud's feature

    • Manual configuration in your MongoDB database

  2. Familiarity with your data structure and fields you want to search on

Steps to create APIs from Template

  1. Navigate to the APIs listing page from Application Layer -> APIs.

  2. Click on the Create API button on the top right corner.

  3. Select the Browse Template option from the dialogue box.

  4. Select the Entity Search APIs option.

  5. Configure the following settings:

    • Select your environment

    • Choose the previously created Search Index

    • Select query fields (fields to be searched)

    • Select filter fields (fields for which unique values will be returned)

  6. Click on finish to generate the starter APIs and models.

You can then customise and edit any APIs that are created via Templates

Generated Components

  • One API method: _search

  • One Request Model

Initially, the API and the model will be created in Draft state. You can edit them in the Workflow builder to add more customisations.

API Method: _search

  • The _search method allows you to search fields based on the provided query.

Query Parameters:

Parameter

Description

Type

Required

query

Text to search on the selected query fields

String

true

limit

Maximum number of records to return

Number

true

offset

Number of records to skip

Number

true

Response

The API returns a JSON object containing:

  • data: Array of matching records according to the query and selected query fields

  • count: Total count of matching records

  • *_filters: Sets of unique values for each selected filter field

    [
      {
          "data": [
              {
                  "_id": "66a67446f6a373b76cae0c04",
                  "title": "Complete Cosmocloud"
              },
              {
                  "_id": "66a67585f6a373b76cb1ebe8",
                  "title": "Try Cosmocloud"
              }
          ],
          "count": [
              {
                  "totalCount": 2
              }
          ],
          "status_filters": [
              {
                  "_id": null,
                  "items": [
                      "PENDING",
                      "COMPLETE"
                  ]
              }
          ]
      }
    ]

    In this example, the API was created with title as a query field, status as a filter field. The query value was Cosmocloud

Best Practices

  • Choose query fields wisely to balance search accuracy and performance.

  • Implement pagination using limit and offset for better performance with large datasets.

  • Regularly update your Search Index to reflect changes in your data structure.

Search Index
How to customise APIs
Search API