Content Search

Content Search allows you to perform more complex content searching and sorting. The feature can be used for the following use cases:

  • Search post by text content

  • Find posts that contain a specific hashtag

  • Sort post by last activity or reaction count

  • Search messages by text content

  • Find messages with mentions

  • Find messages sent by a user

Content Search is currently in Private Beta. Please submit your request to Amity Help Center to enable this feature. It will take approximately 5 business days to process your request.

Search Posts

Search Posts API can be used to search and sort relevant posts created into Amity Social. All APIs will return sorted list of post IDs that contains relevant contents.

API Reference

(V1) Search posts by query as indicated in request JSON body

POST https://beta.amity.services/search/posts

Headers

NameTypeDescription

Authorization*

String

Bearer {accessToken}

(accessToken is retrieved from Amity SDK)

Request Body

NameTypeDescription

apiKey*

String

Your API Key

userId*

String

User ID of the user performing the search

query

JSON

Query JSON (see below)

sort

JSON

Sort JSON (see below)

authToken

String

Authentication token - this is required if Secure Mode is enabled

from

Number

Offset from the first result to be fetched

size

Number

Maximum amount of IDs to be returned

(V2) Search posts by query as indicated in request JSON body

POST https://beta.amity.services/search/v2/posts

Headers

NameTypeDescription

Authorization*

String

Bearer {accessToken}

(accessToken is retrieved from Amity SDK)

Request Body

NameTypeDescription

apiKey*

String

Your API Key

userId*

String

User ID of the user performing the search

query

JSON

Query JSON (see below)

sort

JSON

Sort JSON (see below)

authToken

String

Authentication token - this is required if Secure Mode is enabled

from

Number

Offset from the first result to be fetched

size

Number

Maximum amount of IDs to be returned

Query JSON

query is a JSON object that indicates the posts to be searched for. The following is the full JSON structure with all the fields:

For Search V1:

"query" : {
   "targetId" : ["communityId_1", "communityId_2"], // ID of community to search the posts from
   "targetType" : "community", // Mandatory if targetIds exist
   "text" : "christmas", // Text content to search for
   "sharedCount" : { "gt":10, "lt":20 }, // Number of share of the post in NumberQuery format - Please see NumberQuery section for more detail
   "createdAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // Created time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "updatedAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // last updated time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "hasFlaggedComment" : false, // Boolean whether the posts contain any comments that has been flagged
   "hasFlaggedChildren" : false, // Boolean whether the posts contain any children post that has been flagged
   "postedUserId" : "user_101", //User ID who created the post
   "flagCount" : { "gt":0 }, // Number of flags oon the post in NumberQuery format - Please see NumberQuery section for more detail
   "reactionsCount" : { "gt":10, "lt":20 }, // Number of reactions on the post in NumberQuery format - Please see NumberQuery section for more detail
   "categoryId" : "categoryId_1",// Category of community the post is on
   "lastActivity" : "2021-12-08T15:17:07.965Z", // Last timestamp the post is liked or commented on
   "metadata":{
	   "Field":"text" // Metadata content to search for
   },
   "tags":[
      "tags1",
      "tags2",
      "tags3"
   ]
}

All fields are optional. If targetId is present the system will search for posts on those communities. If targetId is not specified the system will search for all posts created by userId calling the API.

For Search V2:

"query" : {
   "targetId" : ["communityId_1", "communityId_2"], // ID of community to search the posts from
   "targetType" : "community", // Mandatory if targetIds exist
   "text" : "christmas", // Text content to search for
   "sharedCount" : { "gt":10, "lt":20 }, // Number of share of the post in NumberQuery format - Please see NumberQuery section for more detail
   "createdAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // Created time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "updatedAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // last updated time of the post in TimeQuery format - Please see NumberQuery section for more detail
   "hasFlaggedComment" : false, // Boolean whether the posts contain any comments that has been flagged
   "hasFlaggedChildren" : false, // Boolean whether the posts contain any children post that has been flagged
   "postedUserId" : "user_101", //User ID who created the post
   "flagCount" : { "gt":0 }, // Number of flags oon the post in NumberQuery format - Please see NumberQuery section for more detail
   "reactionsCount" : { "gt":10, "lt":20 }, // Number of reactions on the post in NumberQuery format - Please see NumberQuery section for more detail
   "categoryId" : "categoryId_1",// Category of community the post is on
   "lastActivity" : "2021-12-08T15:17:07.965Z", // Last timestamp the post is liked or commented on
   "metadata":{
	   "Field":"text" // Metadata content to search for
   },
   "tags":[
      "tags1",
      "tags2",
      "tags3"
   ]
}

targetType can be the following values:

  • community - search posts in all communities ID as defined in targetId

  • self - search all posts that belongs to the user passed in userId within request body

  • public - search all posts that is in all public communities

Limitations

Current limitations on Search Posts API are

  • Posts created on user feed is not yet searchable.

  • Auth Token and API Key is still needed to call this API instead of using access token.

Search Messages

Search Messages API can be used to search and sort relevant messages created on Amity Chat. All APIs will return sorted list of message IDs of the relevant messages.

API Reference

Search messages by query as indicated in request JSON body

POST https://beta.amity.services/search/messages

Headers

NameTypeDescription

Authorization*

String

Bearer {accessToken}

(accessToken is retrieved from Amity SDK)

Request Body

NameTypeDescription

apiKey*

String

Your API Key

userId*

String

User ID of the user performing the search

query

JSON

Query JSON (see below)

sort

JSON

Sort JSON (see below)

from

Number

Offset from the first result to be fetched

size

Number

Maximum amount of IDs to be returned

Query JSON

query is a JSON object that indicates the message to be searched for. The following is the full JSON structure with all the fields:

"query" : {
   "channelId" : ["channelId_1", "channelId_2"], // ID of channel to search the messages from
   "text" : "christmas", // Text content to search for
   "sharedCount" : { "gt":10, "lt":20 }, // Number of share of the message in NumberQuery format - Please see NumberQuery section for more detail
   "createdAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // Created time of the message in TimeQuery format - Please see NumberQuery section for more detail
   "updatedAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // last updated time of the message in TimeQuery format - Please see NumberQuery section for more detail
   "editedAt" : { "gt":"2021-05-20T04:44:42.334Z" }, // last edited time of the message in TimeQuery format - Please see NumberQuery section for more detail
   "userId" : "user_101", //User ID who sent the message
   "flagCount" : { "gt":0 }, // Number of flags on the message in NumberQuery format - Please see NumberQuery section for more detail
   "channelSegment" : { "gt":0 }, // Channel Segment of the message in NumberQuery format - Please see NumberQuery section for more detail
   "childrenNumber" : { "gt":0 }, // Number of replies to the message in NumberQuery format - Please see NumberQuery section for more detail
   "reactionsCount" : { "gt":10, "lt":20 }, // Number of reactions on the message in NumberQuery format - Please see NumberQuery section for more detail
   "type" : "categoryId_1" // Type of the message
   "tags" : "tags" // Tags of the message
   "isDeleted" : false // Boolean whether the message has been deleted
   "Metadata":{
	"Field":"text" // Metadata content to search for
}
}

All fields are optional. If channelId is present the system will search for posts on those channels. If channelId is not specified the system will search for messages in all channels the user is a member of

Query & Sort Format

NumberQuery

NumberQuery JSON structure defines range of numerical value to look for in a property. Available fields within the JSON structure are:

{
   "gt" : 0, // value of the field must be greater than specific value
   "lt" : 10, // value of the field must be less than specific value
   "gte" : 0, // value of the field must be greater than or equals to specific value
   "lte" : 10 // value of the field must be less than or equals to specific value
}

TimeQuery

TimeQuery JSON structure defines range of date time value to look for in a property. Available fields within the JSON structure are:

{
   "gt" : "2021-08-20T06:26:57.205Z", // value of the field must be after specific date time
   "lt" : "2021-08-31T06:26:57.205Z", // value of the field must be before specific date time
   "gte" : "2021-08-20T06:26:57.205Z", // value of the field must be after than or equals to specific date time
   "lte" : "2021-08-31T06:26:57.205Z" // value of the field must be before than or equals to specific date time
}

Time string in TimeQuery must be in ISO Date Format: YYYY-MM-DDThh:mm:ss.sZ

Sort JSON

sort is a JSON array that indicates how should the returning contents be sorted. The following is the full JSON structure:

[
   "<sort_field>" : { 
      "order" : "asc" // can be 'asc' for ascending order or 'desc' for descending order
   },
   "<sort_field>" : { 
      "order" : "desc" // can be 'asc' for ascending order or 'desc' for descending order
   }
]

The returning content IDs will be sorted by the sort priority defined in Sort JSON. sort_field is the field the post should be sorted by - this can be any of the field Query JSON that is in NumberQuery or TimeQuery format.

Last updated