---
title: "Query"
description: "Query"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/java/reference/query"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-09-08"
---

# 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

Remove header key

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeHeader(key)
```

key of the header you want to remove

## getContentType

Gets the content type

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.getContentType()
```

## where

Add a constraint to fetch all entries that contains given value against specified key

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.where("uid", "entry_uid");
```

key of query parameter

value of query param

## addQuery

Add a custom query against specified key.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addQuery("key", "value");
```

key of query parameter

value of query param

## removeQuery

Remove provided query key from custom query if exist.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeQuery(key);
```

Query name to remove.

## and

Combines all the queries together using AND operator

```
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','something@email.com');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.and(array);
```

List of Query instances on which AND query executes.

## or

Add a constraint to fetch all entries which satisfy any queries.

```
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','something@email.com');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.or(array);
```

the value that provides an upper bound

## lessThan

Add a constraint to the query that requires a particular key entry to be less than the provided value.

```
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");
```

The key to be constrained

the value that provides an upper bound

## lessThanOrEqualTo

Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value

```
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");
```

The key to be constrained

The value that must be equalled.

## greaterThan

Add a constraint to the query that requires a particular key entry to be greater than the provided value.

```
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");
```

The key to be constrained

The value that provides an lower bound.

## greaterThanOrEqualTo

Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.

```
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");
```

The key to be constrained

The list of values the key object should not be.

## notEqualTo

Add a constraint to the query that requires a particular key's entry to be contained in the provided array

```
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");
```

The key to be constrained

The list of values the key object should not be.

## notContainedIn

Add a constraint to the query that requires a particular key's entry to be contained in the provided array

```
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" });
```

The key to be constrained

The list of values the key object should not be.

## notContainedIn

Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.

```
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" });
```

The key to be constrained

The list of values the key object should not be.

## exists

Add a constraint that requires, a specified key exists in response

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.exists("status");
```

The key to be constrained

## notExists

Add a constraint that requires, a specified key does not exists in response.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notExists("status");
```

The key to be constrained

## includeReference

Add a constraint that requires a particular reference key details

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeReference(key);
```

key that to be constraineda

## tags

Include 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" });
```

Comma separated array of tags with which to search entries.

## ascending

Sort the results in ascending order with the given key. <br> Sort the returned entries in ascending order of the provided key.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.ascending(key);
```

The key to order by.

## descending

Sort the results in descending order with the given key. <br> Sort the returned entries in descending order of the provided key.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.descending(key);
```

The key to order by.

## only

Specifies an array of only keys in BASE object that would be included in the response.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.only(new String[]{"name"});
```

## exceptWithReferenceUid

Specifies an array of only keys that would be included in the response

```
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");
```

Array of the only reference keys to be included in response

Key who has reference to some other class object

## exceptWithReferenceUid

Specifies an array of except keys that would be excluded in the response.

```
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

Retrieve count and data of objects in result

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.count();
```

## includeCount

Retrieve count and data of objects in result

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeCount();
```

## includeContentType

Include Content Type of all returned objects along with objects themselves

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeContentType();
```

## includeOwner

Include object owner's profile in the objects data.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeOwner()
```

## skip

The number of objects to skip before returning any.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.skip(3)
```

Number of objects to skip from returned objects

## limit

A limit on the number of objects to return.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.limit(3)
```

Number of objects to limit.

## regex

Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.regex("name", "^browser", "i");
```

The key to be constrained.

The regular expression pattern to match

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

## locale

Set Language using locale code.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.locale("locale-code");
```

language code

## search

This method provides only the entries matching the specified value.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.search("header");
```

value used to match or compare

## find

Execute a Query and Caches its result (Optional)

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.find(new QueryResultsCallBack() {
@Override 
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {

 }
});
```

QueryResultsCallBack object to notify the application when the request has completed.

## findOne

This Execute a Query and Caches its result (Optional)

```
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) {
  }
});
```

The key as string which needs to be added to the Query

## addParam

This method adds key and value to an Entry. Parameters

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addParam(key, value);
```

The key as string which needs to be added to the Query

The value as string which needs to be added to the Query

## includeReferenceContentTypUid

This method also includes the content type UIDs of the referenced entries returned in the response

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.includeReferenceContentTypUid()
```

## whereNotIn

Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query conditions made on referenced fields.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereIn("due_date", <span>query</span>);
```

The key to be constrained

queryObject is Query object, so you can chain this call

## whereNotIn

Get entries having values based on referenced fields. This query works the opposite of $in\_query and retrieves all entries that does not satisfy query conditions made on referenced fields.

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereNotIn("due_date", query);
```

The key to be constrained

Query object, so you can chain this call

## includeFallback

Includes language fallback in the query response

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeFallback();
```

## includeEmbeddedItems

Includes 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

Includes Branch in the entry response

```
import com.contentstack.sdk.*;

Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
entry.includeBranch();
```

## includeMetadata

Includes query metadata along with the response body.

```
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
Query query = stack.contentType("contentTypeUid").query();
query.includeMetadata();
```

## Query | Java Delivery SDK | Contentstack

Query fetches all entries of a content type in the Java Delivery SDK, returning JSON content with support for filters, environment, and locale.