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
Created a Search Index in your database using either:
Cosmocloud's Search Index feature
Manual configuration in your MongoDB database
Familiarity with your data structure and fields you want to search on
Steps to create APIs from Template
Navigate to the APIs listing page from Application Layer -> APIs.
Click on the Create API button on the top right corner.
Select the Browse Template option from the dialogue box.
Select the Entity Search APIs option.
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)
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
_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 fieldscount
: Total count of matching records*_filters
: Sets of unique values for each selected filter fieldIn this example, the API was created with
title
as a query field,status
as a filter field. Thequery
value wasCosmocloud
Best Practices
Choose query fields wisely to balance search accuracy and performance.
Implement pagination using
limit
andoffset
for better performance with large datasets.Regularly update your Search Index to reflect changes in your data structure.
Last updated