Query data
This article contains the main principles for querying data in evitaDB, the description of the data API regarding entity fetching and related recommendations.
The query in evitaDB is represented by a tree of nested "constraints" divided into four parts:
- collection
- it identifies the collection to query
- filterBy
- it limits the number of results returned
- orderBy
- it specifies the order in which the results are returned
- require
- it allows you to pass additional information about how much data the returned entities should have, (how complete the returned entity should be) how many of them are needed, and what other calculations should be performed on them
The evitaQL (evitaDB Query Language) entry point is represented by
class, and looks like this
a Lisp flavored language. It always starts with
the name of the constraint, followed by a set of arguments in parentheses. You can even use other functions
in those arguments. An example of such a query might look like this:
The query will return the first page of 20 products in the category "local food" and its subcategories that have Czech localization and a valid price in one of the price lists "VIP", "loyal customer" or "regular prices" in the currency CZK. It also filters only products with a selling price between 600 and 1,600 CZK including VAT and with the parameters "gluten-free" and "original recipe".
The so-called price histogram will also be calculated for all matching products with a maximum of 30 columns so that they can be displayed on the dedicated space. In addition, a summary of parametric filters (facets )will be calculated with an impact analysis of how the result would look if the user selected some other parameters in addition to the two selected ones.
evitaQL is represented by a simple
String which is parsed to
an abstract syntax tree consisting of constraints
() encapsulated in
object.
We have designed the evitaQL string representation to look similar to a query defined directly in the Java language.
We also try to preserve the "look & feel" of the original evitaQL in different languages / APIs like REST, GraphQL or C#
while respecting the conventions and capabilities of the respective language.
evitaQL is used in the gRPC protocol and can optionally be used for the embedded Java environment. It can also be used
in evitaDB console. The GraphQL and REST Web API use a similar format, but adapted to
the protocol conventions (so that we can take advantage of the Open API / GQL schema).