OJAI Query Syntax
OJAI defines a syntax for specifying queries on JSON documents. You can use this syntax in Node.js and Python OJAI client applications and HPE Ezmeral Data Fabric Database shell.
See Query with --query to learn about how to use this syntax in HPE Ezmeral Data Fabric Database shell.
An OJAI query can include the following components:
You can specify some or all these components in a query, separating each component with a comma.
OJAI Query Projection
- Syntax
-
"$select":"fieldpath"
"$select":["fieldpath1","fieldpath2",...]
- Description
-
The projection is the list of field paths to select in your query. You can specify a single field path or multiple. When specifying multiple, use an array notation to list the field paths.
See JSON Document Field Paths for more information about the syntax of different JSON document field paths.
- Examples
-
Single field path:
"$select":"a.c.d"
Multiple field paths:
"$select":["a.c.d", "a.c.e", "m[0]"]
OJAI Query Condition
- Syntax
-
"$where":OJAIQueryCondition
- Description
-
The condition filters your query result. See OJAI Query Condition Syntax for more information about the syntax of an OJAIQueryCondition.
- Example
-
If you have the following condition:
(a.b.[0].boolean == false && (a.c.d != 5 || a.b[1].decimal > 1 || a.b[1].decimal < 10))
This is the OJAI JSON syntax for the condition:
"$where":{ "$and":[ {"$eq":{"a.b[0].boolean":false}}, {"$or":[ {"$ne":{"a.c.d":5}}, {"$gt":{"a.b[1].decimal":1}}, {"$lt":{"a.b[1].decimal":10}} ] } ] }
OJAI Query Order By
- Syntax
-
"$orderby":"fieldpath"
"$orderby":{"fieldpath":"order"}
"$orderby":[fieldpath1,fieldpath2,...]
"$orderby":[{"fieldpath1":"order"},{"fieldpath2":"order"},...]
- Description
-
The order by specifies the field paths on which to sort your query result. You can specify a single field path or multiple. When specifying multiple, use an array notation to list the field paths. For each field path, you can optionally specify an order of either
asc
ordesc
. Both order keywords are case insensitive. The default isasc
. When specifying an order, enclose the fieldpath and order with curly braces. - Examples
-
Order on a single field path in the default
asc
order:"$orderby":"a.c.e"
Order on a single field path in the
desc
order:"$orderby":{"a.c.e":"desc"}
Order on two field paths, where the second specifies a
desc
order:"$orderby":["a.c.d",{"a.c.e":"desc"}]
OJAI Query Limit
- Syntax
-
"$limit":positive-integer
- Description
-
The number of documents to return from the query.
- Example
-
Return only ten documents:
"$limit:10
OJAI Query Offset
- Syntax
-
"$offset":positive-integer
- Description
-
The number of documents to skip before returning results to the client. The offset value has a direct effect on query time; as the offset value increases, query time also increases.
- Example
-
Process the query and skip the first five documents in the result set before returning the results to the client.
"$offset":5
OJAI Query Options
- Syntax
-
"$options":{optionName:optionValue}
"$options":[{optionName1:optionValue1},{optionName2:optionValue2},...]
- Description
-
Settings that influence a query's execution path. See OJAI Query Options for a list of available options.
When specifying the
optionName
, you must separate the components of the option name, replacing the dots with curly braces and colons and enclosing each component in quotes. - Example
-
Force the query to use the OJAI Distributed Query Service by setting the
ojai.mapr.query.force-drill
option:"$options":{"ojai":{"mapr":{"query":{"force-drill":true}}}}