Entity Search APIs

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 Search Index 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

How to customise APIs

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.

  • 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.

Last updated