Search in sources :

Example 16 with QueryVariant

use of co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant in project para-search-elasticsearch by Erudika.

the class ESUtils method convertQueryStringToNestedQuery.

/**
 * Convert a normal query string query to one which supports nested fields.
 * Reference: https://github.com/elastic/elasticsearch/issues/11322
 * @param query query string
 * @return a list of composite queries for matching nested objects
 */
static QueryVariant convertQueryStringToNestedQuery(String query) {
    // nested array syntax
    String queryStr = StringUtils.trimToEmpty(query).replaceAll("\\[(\\d+)\\]", "-$1");
    Query q = qsParsed(queryStr);
    if (q == null) {
        return QueryBuilders.matchAll().build();
    }
    try {
        return rewriteQuery(q, 0);
    } catch (Exception e) {
        logger.warn(e.getMessage());
        return null;
    }
}
Also used : Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) BoolQuery(co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) MatchAllQuery(co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery) RangeQuery(co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery) QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) IOException(java.io.IOException)

Aggregations

QueryVariant (co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant)15 BoolQuery (co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery)12 ParaObject (com.erudika.para.core.ParaObject)11 FieldValue (co.elastic.clients.elasticsearch._types.FieldValue)10 SortOptions (co.elastic.clients.elasticsearch._types.SortOptions)10 SortOrder (co.elastic.clients.elasticsearch._types.SortOrder)10 ChildScoreMode (co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode)10 QueryBuilders (co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders)10 BulkOperation (co.elastic.clients.elasticsearch.core.bulk.BulkOperation)10 App (com.erudika.para.core.App)10 DAO (com.erudika.para.core.persistence.DAO)10 Config (com.erudika.para.core.utils.Config)10 Pager (com.erudika.para.core.utils.Pager)10 Para (com.erudika.para.core.utils.Para)10 Utils (com.erudika.para.core.utils.Utils)10 ArrayList (java.util.ArrayList)10 SearchType (co.elastic.clients.elasticsearch._types.SearchType)7 Like (co.elastic.clients.elasticsearch._types.query_dsl.Like)7 Query (co.elastic.clients.elasticsearch._types.query_dsl.Query)7 HashMap (java.util.HashMap)7