Query
Query
The Get all entries request fetches the list of all the entries of a particular content type. It returns the content of each entry in JSON format. You need to specify the environment and locale of which you want to get the entries. We can apply filters on query also.
removeHeader
The removeHeader method removes a header from the request using the specified header key.
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of the header you want to remove |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeHeader(key)getContentType
The getContentType method retrieves the content type associated with the request.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.getContentType()where
The where method filters entries by applying a condition that matches a specified field key with the provided value.
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of query parameter |
| value (required) | Object | value of query param |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.where("uid", "entry_uid");addQuery
The addQuery method adds a custom key-value pair to the query URL, enabling support for extended or non-standard query parameters.
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of query parameter |
| value (required) | String | value of query param |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addQuery("key", "value");removeQuery
Remove provided query key from custom query if exist.
| Name | Type | Description |
|---|---|---|
| key (required) | String | Query name to remove. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeQuery(key);and
The and method combines multiple queries using the AND operator to retrieve results that meet all specified conditions.
| Name | Type | Description |
|---|---|---|
| queryObjects (required) | ArrayList<Query> | List of Query instances on which AND query executes. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");
Query query = projectClass.query();
query.where('username','something');
Query subQuery = projectClass.query();
subQuery.where('email_address','[email protected]');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.and(array);or
The or method retrieves all entries that meet any of the specified queries by combining them using the OR operator.
| Name | Type | Description |
|---|---|---|
| queryObjects (required) | ArrayList<Query> | the value that provides an upper bound |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");
Query query = projectClass.query();
query.where('username','something');
Query subQuery = projectClass.query();
subQuery.where('email_address','[email protected]');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.or(array);lessThan
The lessThan method applies a constraint that requires a specified key to have a value lower than the given value to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | the value that provides an upper bound |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");lessThanOrEqualTo
The lessThanOrEqualTo method applies a constraint that requires a specified key to have a value less than or equal to the given value to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The value that must be equalled. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");greaterThan
The greaterThan method applies a constraint that requires a specified key to have a value greater than the given value to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The value that provides an lower bound. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.greaterThan("due_date", "2013-06-25T00:00:00+05:30");greaterThanOrEqualTo
The greaterThanOrEqualTo method applies a constraint that requires a specified key to have a value greater than or equal to the given value to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.greaterThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");notEqualTo
The notEqualTo method applies a constraint that requires a specified key to have a value not equal to the given value to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notEqualTo("due_date", "2013-06-25T00:00:00+05:30");containedIn
The containedIn method retrieves entries by applying a constraint that requires a specified key to have a value contained within the provided array.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object[] | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.containedIn("severity", new Object[] { "Show Stopper", "Critical" });notContainedIn
The notContainedIn method retrieves entries by applying a constraint that requires a specified key to have a value not contained within the provided array.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object[] | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notContainedIn("severity", new Object[] { "Show Stopper", "Critical" });exists
The exists method applies a constraint that requires a specified key to be present in the response to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.exists("status");notExists
The notExists method applies a constraint that requires a specified key to be absent from the response to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notExists("status");includeReference
The includeReference method adds a constraint that includes the details of a specified reference key in the response to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | key that to be constraineda |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeReference(key);tags
The tags method includes the specified tags as a search criterion in the query to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String[] | Comma separated array of tags with which to search entries. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.tags(new String[] { "tag1", "tag2" });ascending
The ascending method sorts the results in ascending order based on the specified key to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to order by. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.ascending(key);descending
The descending method sorts the results in descending order based on the specified key to retrieve entries.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to order by. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.descending(key);only
The only method retrieves entries by specifying an array of keys in the base object that should be included in the response.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | String[] | Pass the field UID. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
<span>query.only(new String[]{"name"});</span>onlyWithReferenceUid
The onlyWithReferenceUid method retrieves entries by specifying an array of only keys that should be included in the response for referenced entries.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | ArrayList<String> | Array of the only reference keys to be included in response |
| referenceFieldUid (required) | String | Key who has reference to some other class object |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
ArrayList<String> array = new ArrayList<String>();
array.add("description");
query.onlyWithReferenceUid(array, "for_bug");exceptWithReferenceUid
The exceptWithReferenceUid method retrieves entries by specifying an array of except keys that should be excluded from the response for referenced entries.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
ArrayList<String> array = new ArrayList<String>();
array.add("description");
query.exceptWithReferenceUid(array, "for_bug");count
The count method retrieves the total count along with the data objects that match the query criteria.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.count();includeCount
The includeCount method retrieves the count of objects along with the data in the response that match the specified query conditions.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeCount();includeContentType
The includeContentType method retrieves objects along with the content type details of all returned objects in the response.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeContentType();includeOwner
The includeOwner method retrieves objects by including the owner’s profile information in each object’s data.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.<span>includeOwner</span>()skip
The skip method retrieves objects by skipping a specified number of objects before returning the results.
| Name | Type | Description |
|---|---|---|
| number (required) | int | Number of objects to skip from returned objects |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(<span>context, </span>apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.skip(3);limit
The limit method retrieves entries by setting a limit on the number of objects to return.
| Name | Type | Description |
|---|---|---|
| number (required) | int | Number of objects to limit. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.limit(3)regex
The regex method retrieves entries by applying a regular expression constraint that matches string values against the provided pattern, which may result in slower performance for large data sets.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained. |
| regex (required) | String | The regular expression pattern to match |
| modifiers | Any of the following supported Regular expression modifiers. - use i for case-insensitive matching. - use m for making dot match newlines. - use x for ignoring whitespace in regex |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.regex("name", "^browser", "i");locale
The locale method retrieves entries by setting the language based on a specified locale code.
| Name | Type | Description |
|---|---|---|
| locale (required) | String | language code |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.locale("locale-code");search
The search method retrieves only the entries that match the specified search value.
| Name | Type | Description |
|---|---|---|
| value (required) | String | value used to match or compare |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.search("header");findOne
The findOne method retrieves entries that match the query conditions and optionally caches the result to improve performance.
| Name | Type | Description |
|---|---|---|
| callBack (required) | SingleQueryResultCallback | The key as string which needs to be added to the Query |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.findOne(new QueryResultsCallBack() {
Override public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
}
});addParam
The addParam method adds a key–value parameter to an entry request.
| Name | Type | Description |
|---|---|---|
| paramKey (required) | String | The key as string which needs to be added to the Query |
| paramValue (required) | String | The value as string which needs to be added to the Query |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addParam(key, value);includeReferenceContentTypUid
The includeReferenceContentTypeUid method retrieves entries by including the content type UIDs of referenced entries in the response.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.includeReferenceContentTypUid()whereIn
The whereIn method retrieves entries by applying conditions to referenced fields and returns those that match the specified values.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| queryObject (required) | Query | queryObject is Query object, so you can chain this call |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereIn("due_date", query);whereNotIn
The whereNotIn method retrieves entries by applying conditions to referenced fields and returns those that do not match the specified values, functioning as the opposite of the $in query.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| queryObject (required) | Query | Query object, so you can chain this call |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereNotIn("due_date", query);includeFallback
The includeFallback method retrieves entries by including fallback language content in the response when content for the specified locale is unavailable.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(<span>context, </span>apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeFallback();includeEmbeddedItems
The includeEmbeddedItems method retrieves entries by including embedded items in the query response.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeEmbeddedItems();includeBranch
The includeBranch method retrieves entries by including branch information in the response.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(context,apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
<span>entry.includeBranch();includeMetadata
The includeMetadata method retrieves entries by including query metadata in the response body.
Stack stack = Contentstack.stack(context, "apiKey", "deliveryToken", environment_name);
Query query = stack.contentType("contenTypeUid").query();
query.includeMetadata();