Creating an OJAI QueryCondition Object

The Java OJAI client supports a QueryCondition interface. After you create a QueryCondition object, call methods in the class to construct your query condition.

Creating a QueryCondition Object

Java OJAI provides a method for specifying query conditions. The method takes three arguments:

  • The field path to apply the condition to
  • The condition operator, represented as a QueryCondition.Op
  • The value to compare the field path against

The field path is either a field in a JSON document, a subfield within a nested document, or an array element.

Depending on the type of the field path, you specify the comparison value as follows:

Scalar Data
You can specify the value using either a Java typed value (for example, int, float, or String) or a Java OJAI object. The API supports the following OJAI types:
  • ODate
  • OInterval
  • OTime
  • OTimestamp
Nested Documents
You can specify only equality and non-equality conditions on nested documents. You specify the nested document using a Java Map object. In the case of equality, all of the fields in the nested document must match. The order of the fields is not relevant.
You can specify only equality and non-equality conditions on arrays. You specify an array using a Java List object. In the case of equality, the order of the elements and the element values must match.

In addition to, QueryCondition also supports the following methods:

QueryCondition Method Description


Match for equality or non-equality on nested documents and arrays
in() Search for individual elements in an array
like() Search for string values using SQL LIKE expressions


Search for string values using regular expressions.

You can use regular expressions that compose the Perl-Compatible Regular Expressions (PCRE) library as well as a subset of the regular expressions that are supported in java.util.regex.pattern. See HBase Java Regular Expressions Support for a list of supported regular expressions.

and() Begins a new AND condition block
or() Begins a new OR condition block
close() Closes a compound condition block
build() Builds the condition
Note: The material described in this section is a subset of the QueryCondition API. It introduces you to the basics of the API. For the complete API, see the QueryCondition interface.

Example: Creating a QueryCondition Object

The following example shows how to define a QueryCondition object for this query condition:

(a.b.[0].boolean == false && (a.c.d != 5 || a.b[1].decimal > 1 || a.b[1].decimal < 10))
QueryCondition qc = connection.newCondition()
        .is("a.b[0].boolean", Op.EQUAL, false)
            .is("a.c.d", Op.NOT_EQUAL, 5)
            .is("a.b[1].decimal", Op.GREATER, 1)
            .is("a.b[1].decimal", Op.LESS, 10)

Pass the QueryCondition object to the Query.where method. For a complete Java code example, see the Java - OJAI QueryCondition Object example at Querying with Conditions.