Class QueryBuilders


  • class QueryBuilders
    extends java.lang.Object
    Utility class to generate elastic search queries. Most query builders have been copied from ES distribution. The reason we have separate definition is high-level client dependency on core modules (like lucene, netty, XContent etc.) which is not compatible between different major versions.

    The goal of ES adapter is to be compatible with any elastic version or even to connect to clusters with different versions simultaneously.

    Jackson API is used to generate ES query as JSON document.

    • Constructor Detail

      • QueryBuilders

        private QueryBuilders()
    • Method Detail

      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        java.lang.String value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        int value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        char value)
        A Query that matches documents containing a single character term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        long value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        float value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        double value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        boolean value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termQuery

        static QueryBuilders.TermQueryBuilder termQuery​(java.lang.String name,
                                                        java.lang.Object value)
        A Query that matches documents containing a term.
        Parameters:
        name - The name of the field
        value - The value of the term
      • termsQuery

        static QueryBuilders.TermsQueryBuilder termsQuery​(java.lang.String name,
                                                          java.lang.Iterable<?> values)
        A filer for a field based on several terms matching on any of them.
        Parameters:
        name - The field name
        values - The terms
      • rangeQuery

        static QueryBuilders.RangeQueryBuilder rangeQuery​(java.lang.String name)
        A Query that matches documents within an range of terms.
        Parameters:
        name - The field name
      • regexpQuery

        static QueryBuilders.RegexpQueryBuilder regexpQuery​(java.lang.String name,
                                                            java.lang.String regexp)
        A Query that matches documents containing terms with a specified regular expression.
        Parameters:
        name - The name of the field
        regexp - The regular expression
      • constantScoreQuery

        static QueryBuilders.ConstantScoreQueryBuilder constantScoreQuery​(QueryBuilders.QueryBuilder queryBuilder)
        A query that wraps another query and simply returns a constant score equal to the query boost for every document in the query.
        Parameters:
        queryBuilder - The query to wrap in a constant score query
      • existsQuery

        static QueryBuilders.ExistsQueryBuilder existsQuery​(java.lang.String name)
        A filter to filter only documents where a field exists in them.
        Parameters:
        name - The name of the field
      • writeObject

        private static void writeObject​(com.fasterxml.jackson.core.JsonGenerator generator,
                                        java.lang.Object value)
                                 throws java.io.IOException
        Write usually simple (scalar) value (string, number, boolean or null) to json output. In case of complex objects delegates to jackson serialization.
        Parameters:
        generator - api to generate JSON document
        value - JSON value to write
        Throws:
        java.io.IOException - if can't write to output