Entity Search APIs
Last updated
Last updated
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
Created a Search Index in your database using either:
Cosmocloud's feature
Manual configuration in your MongoDB database
Familiarity with your data structure and fields you want to search on
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.
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.
_search
The _search
method allows you to search fields based on the provided query.
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
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
In this example, the API was created with title
as a query field, status
as a filter field. The query
value was Cosmocloud
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.