Advanced Filtering and Searching
This section will describe advanced usage of the Android and Java API, in order to filter, sort and order responses. The
upcoming samples are using the following setup: space id = cfexampleapi and api token = b4c0n73n7fu1.
Searching
In order query for all items, containing the complete string nyan in symbol or text fields.
Inexact searches
If you want to search for just a part of a text, you could use a match operator. Keep in mind, you have to define
the field to be matched, so it won’t work on all fields automatically. Also for this request to work, you have to
specify a content type to look for:
Order
In order to order a result by a field, you need to specify order as a where selector. Please make sure, that you
either just query for fields in sys, or specify a content type to look for.
If you want to invert the result order, feel free to add a - in front of the field to be looked for:
Having a result ordered in more then one level, take a look at this snippet:
Limit
To retrieve a given amount of elements, you can use the limit parameter.
Ignoring the first entries, can be accomplished by using the skip parameter. This can be used nicely for paging, by
skipping the first 13 elements:
Include
If you do not want the query to return only top level entries, and not its children, you could use the
parameter include with the value 0. Otherwise this value will be used to determine how many hierarchy levels
to be returned. If not set, it will return 1, only the first level of children.
Sequences
Do you want to get elements based on a set of possibilities? Then you came to the right place:
Will return all elements whose sys.id is either finn or jake.
If you want to invert this query, you would use the a nin (for notin) operator in the query:
Existence
Querying for all entries having a specific field set to something (aka it is existing), you would issue a request like:
Mathematical comparisons
Contentful is also able to query entries, based on a mathematical comparison operator:
This will return all entries with the birthday less or equal then 1980-01-01. Other operators are available too,
see REST API doc
Inequality
If you want to filter out specific items, you should be thinking about using the [ne] operator:
Location
Did you ever want to query based on a real world location? This is how to do this in java:
Which will return the list of results ordered by distance, the closest first.
If you would rather find out if there are entries in a specific area of the world, you could be using something like this:
returning all elements whose center is in the given area. (Do not forget the content_type)
Assets mimetype
This last example will tell you how to query for assets, which are only of a specific mimetype: