Search in sources :

Example 6 with QueryVariant

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

the class ESUtils method deleteByQuery.

/**
 * Executes a delete_by_query request to ES and refreshes the index.
 * @param appid the appid / index alias
 * @param fb query
 * @param cb callback
 * @return number of unindexed documents.
 */
public static long deleteByQuery(String appid, QueryVariant fb, Consumer<DeleteByQueryResponse> cb) {
    int batchSize = Para.getConfig().getConfigInt("unindex_batch_size", 1000);
    boolean isSharingIndex = !App.isRoot(appid) && StringUtils.startsWith(appid, " ");
    String indexName = getIndexName(appid);
    DeleteByQueryRequest.Builder deleteByQueryReq = new DeleteByQueryRequest.Builder();
    deleteByQueryReq.index(indexName);
    deleteByQueryReq.conflicts(Conflicts.Proceed);
    deleteByQueryReq.query(fb._toQuery());
    // deleteByQueryReq.BatchSize(batchSize);
    // parallelize operation?
    deleteByQueryReq.slices(1L);
    deleteByQueryReq.scroll(Time.of(t -> t.time("10m")));
    deleteByQueryReq.refresh(true);
    if (isSharingIndex) {
        deleteByQueryReq.routing(indexName);
    }
    if (cb != null) {
        // getRESTClient().deleteByQueryAsync(deleteByQueryReq, RequestOptions.DEFAULT, cb);
        getAsyncRESTClient().deleteByQuery(deleteByQueryReq.build()).thenAccept(cb);
    } else {
        DeleteByQueryResponse res;
        try {
            res = getRESTClient().deleteByQuery(deleteByQueryReq.build());
            if (!res.failures().isEmpty()) {
                logger.warn("Failures in deleteByQuery() - {}", res.failures().iterator().next().cause().reason());
            }
            return res.total();
        } catch (IOException ex) {
            logger.error(null, ex);
        }
    }
    return 0L;
}
Also used : Query(org.apache.lucene.search.Query) BulkOperation(co.elastic.clients.elasticsearch.core.bulk.BulkOperation) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Term(org.apache.lucene.index.Term) LoggerFactory(org.slf4j.LoggerFactory) TrackHits(co.elastic.clients.elasticsearch.core.search.TrackHits) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.http.Header) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Matcher(java.util.regex.Matcher) Map(java.util.Map) FieldValue(co.elastic.clients.elasticsearch._types.FieldValue) DestroyListener(com.erudika.para.core.listeners.DestroyListener) Config(com.erudika.para.core.utils.Config) Conflicts(co.elastic.clients.elasticsearch._types.Conflicts) JsonData(co.elastic.clients.json.JsonData) ParaObject(com.erudika.para.core.ParaObject) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpEntity(org.apache.http.HttpEntity) PrefixQuery(org.apache.lucene.search.PrefixQuery) AddAction(co.elastic.clients.elasticsearch.indices.update_aliases.AddAction) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) TypeMapping(co.elastic.clients.elasticsearch._types.mapping.TypeMapping) HttpRequest(org.apache.http.HttpRequest) WildcardQuery(org.apache.lucene.search.WildcardQuery) Objects(java.util.Objects) QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) List(java.util.List) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) ObjectBuilder(co.elastic.clients.util.ObjectBuilder) BulkResponse(co.elastic.clients.elasticsearch.core.BulkResponse) Entry(java.util.Map.Entry) Para(com.erudika.para.core.utils.Para) Pattern(java.util.regex.Pattern) HealthStatus(co.elastic.clients.elasticsearch._types.HealthStatus) QueryBuilders(co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders) NameValuePair(org.apache.http.NameValuePair) CredentialsProvider(org.apache.http.client.CredentialsProvider) JacksonJsonpMapper(co.elastic.clients.json.jackson.JacksonJsonpMapper) App(com.erudika.para.core.App) ElasticsearchAsyncClient(co.elastic.clients.elasticsearch.ElasticsearchAsyncClient) RestClientTransport(co.elastic.clients.transport.rest_client.RestClientTransport) Sysprop(com.erudika.para.core.Sysprop) RestClient(org.elasticsearch.client.RestClient) IndexAliases(co.elastic.clients.elasticsearch.indices.get_alias.IndexAliases) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) Aws4SignerParams(software.amazon.awssdk.auth.signer.params.Aws4SignerParams) HashMap(java.util.HashMap) ChildScoreMode(co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode) Pager(com.erudika.para.core.utils.Pager) DeleteByQueryResponse(co.elastic.clients.elasticsearch.core.DeleteByQueryResponse) ArrayList(java.util.ArrayList) DeleteByQueryRequest(co.elastic.clients.elasticsearch.core.DeleteByQueryRequest) Action(co.elastic.clients.elasticsearch.indices.update_aliases.Action) DAO(com.erudika.para.core.persistence.DAO) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) LinkedList(java.util.LinkedList) Region(software.amazon.awssdk.regions.Region) BoolQuery(co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery) Property(co.elastic.clients.elasticsearch._types.mapping.Property) Refresh(co.elastic.clients.elasticsearch._types.Refresh) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) Time(co.elastic.clients.elasticsearch._types.Time) Logger(org.slf4j.Logger) SortOrder(co.elastic.clients.elasticsearch._types.SortOrder) Aws4Signer(software.amazon.awssdk.auth.signer.Aws4Signer) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser) IndexSettings(co.elastic.clients.elasticsearch.indices.IndexSettings) IOException(java.io.IOException) Utils(com.erudika.para.core.utils.Utils) BooleanClause(org.apache.lucene.search.BooleanClause) Operator(co.elastic.clients.elasticsearch._types.query_dsl.Operator) Consumer(java.util.function.Consumer) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) BooleanQuery(org.apache.lucene.search.BooleanQuery) AuthScope(org.apache.http.auth.AuthScope) HttpContext(org.apache.http.protocol.HttpContext) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) NumberUtils(org.apache.commons.lang3.math.NumberUtils) MatchAllQuery(co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery) ElasticsearchClient(co.elastic.clients.elasticsearch.ElasticsearchClient) QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant) SortOptions(co.elastic.clients.elasticsearch._types.SortOptions) RemoveAction(co.elastic.clients.elasticsearch.indices.update_aliases.RemoveAction) Collections(java.util.Collections) HttpHost(org.apache.http.HttpHost) RangeQuery(co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery) InputStream(java.io.InputStream) DeleteByQueryResponse(co.elastic.clients.elasticsearch.core.DeleteByQueryResponse) DeleteByQueryRequest(co.elastic.clients.elasticsearch.core.DeleteByQueryRequest) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) ObjectBuilder(co.elastic.clients.util.ObjectBuilder) IOException(java.io.IOException)

Example 7 with QueryVariant

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

the class ESUtils method fuzzy.

private static ObjectBuilder<?> fuzzy(Query q) {
    ObjectBuilder<?> qb;
    String field = ((FuzzyQuery) q).getTerm().field();
    String value = ((FuzzyQuery) q).getTerm().text();
    if (StringUtils.isBlank(field)) {
        QueryVariant kQuery = QueryBuilders.matchAll().build();
        QueryVariant vQuery = QueryBuilders.fuzzy().field(getValueFieldName(value)).value(v -> v.stringValue(value)).build();
        QueryVariant nested = (QueryVariant) nestedPropsQuery(QueryBuilders.bool().must(kQuery._toQuery(), vQuery._toQuery()).build());
        qb = QueryBuilders.bool().should(nested._toQuery(), QueryBuilders.multiMatch().query(value).build()._toQuery());
    } else if (field.matches(PROPS_REGEX)) {
        qb = nestedPropsQuery(keyValueBoolQuery(field, QueryBuilders.fuzzy().field(getValueFieldName(value)).value(v -> v.stringValue(value)).build()));
    } else {
        qb = QueryBuilders.fuzzy().field(field).value(v -> v.stringValue(value));
    }
    return qb;
}
Also used : Query(org.apache.lucene.search.Query) BulkOperation(co.elastic.clients.elasticsearch.core.bulk.BulkOperation) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Term(org.apache.lucene.index.Term) LoggerFactory(org.slf4j.LoggerFactory) TrackHits(co.elastic.clients.elasticsearch.core.search.TrackHits) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.http.Header) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Matcher(java.util.regex.Matcher) Map(java.util.Map) FieldValue(co.elastic.clients.elasticsearch._types.FieldValue) DestroyListener(com.erudika.para.core.listeners.DestroyListener) Config(com.erudika.para.core.utils.Config) Conflicts(co.elastic.clients.elasticsearch._types.Conflicts) JsonData(co.elastic.clients.json.JsonData) ParaObject(com.erudika.para.core.ParaObject) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpEntity(org.apache.http.HttpEntity) PrefixQuery(org.apache.lucene.search.PrefixQuery) AddAction(co.elastic.clients.elasticsearch.indices.update_aliases.AddAction) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) TypeMapping(co.elastic.clients.elasticsearch._types.mapping.TypeMapping) HttpRequest(org.apache.http.HttpRequest) WildcardQuery(org.apache.lucene.search.WildcardQuery) Objects(java.util.Objects) QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) List(java.util.List) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) ObjectBuilder(co.elastic.clients.util.ObjectBuilder) BulkResponse(co.elastic.clients.elasticsearch.core.BulkResponse) Entry(java.util.Map.Entry) Para(com.erudika.para.core.utils.Para) Pattern(java.util.regex.Pattern) HealthStatus(co.elastic.clients.elasticsearch._types.HealthStatus) QueryBuilders(co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders) NameValuePair(org.apache.http.NameValuePair) CredentialsProvider(org.apache.http.client.CredentialsProvider) JacksonJsonpMapper(co.elastic.clients.json.jackson.JacksonJsonpMapper) App(com.erudika.para.core.App) ElasticsearchAsyncClient(co.elastic.clients.elasticsearch.ElasticsearchAsyncClient) RestClientTransport(co.elastic.clients.transport.rest_client.RestClientTransport) Sysprop(com.erudika.para.core.Sysprop) RestClient(org.elasticsearch.client.RestClient) IndexAliases(co.elastic.clients.elasticsearch.indices.get_alias.IndexAliases) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) Aws4SignerParams(software.amazon.awssdk.auth.signer.params.Aws4SignerParams) HashMap(java.util.HashMap) ChildScoreMode(co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode) Pager(com.erudika.para.core.utils.Pager) DeleteByQueryResponse(co.elastic.clients.elasticsearch.core.DeleteByQueryResponse) ArrayList(java.util.ArrayList) DeleteByQueryRequest(co.elastic.clients.elasticsearch.core.DeleteByQueryRequest) Action(co.elastic.clients.elasticsearch.indices.update_aliases.Action) DAO(com.erudika.para.core.persistence.DAO) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) LinkedList(java.util.LinkedList) Region(software.amazon.awssdk.regions.Region) BoolQuery(co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery) Property(co.elastic.clients.elasticsearch._types.mapping.Property) Refresh(co.elastic.clients.elasticsearch._types.Refresh) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) Time(co.elastic.clients.elasticsearch._types.Time) Logger(org.slf4j.Logger) SortOrder(co.elastic.clients.elasticsearch._types.SortOrder) Aws4Signer(software.amazon.awssdk.auth.signer.Aws4Signer) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser) IndexSettings(co.elastic.clients.elasticsearch.indices.IndexSettings) IOException(java.io.IOException) Utils(com.erudika.para.core.utils.Utils) BooleanClause(org.apache.lucene.search.BooleanClause) Operator(co.elastic.clients.elasticsearch._types.query_dsl.Operator) Consumer(java.util.function.Consumer) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) BooleanQuery(org.apache.lucene.search.BooleanQuery) AuthScope(org.apache.http.auth.AuthScope) HttpContext(org.apache.http.protocol.HttpContext) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) NumberUtils(org.apache.commons.lang3.math.NumberUtils) MatchAllQuery(co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery) ElasticsearchClient(co.elastic.clients.elasticsearch.ElasticsearchClient) QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant) SortOptions(co.elastic.clients.elasticsearch._types.SortOptions) RemoveAction(co.elastic.clients.elasticsearch.indices.update_aliases.RemoveAction) Collections(java.util.Collections) HttpHost(org.apache.http.HttpHost) RangeQuery(co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery) InputStream(java.io.InputStream) QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant)

Example 8 with QueryVariant

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

the class ESUtils method wildcard.

private static ObjectBuilder<?> wildcard(Query q) {
    ObjectBuilder<?> qb;
    String field = ((WildcardQuery) q).getTerm().field();
    String value = ((WildcardQuery) q).getTerm().text();
    if (StringUtils.isBlank(field)) {
        QueryVariant kQuery = QueryBuilders.matchAll().build();
        QueryVariant vQuery = QueryBuilders.wildcard().field(getValueFieldName(value)).value(value).build();
        QueryVariant nested = (QueryVariant) nestedPropsQuery(QueryBuilders.bool().must(kQuery._toQuery(), vQuery._toQuery()).build());
        qb = QueryBuilders.bool().should(nested._toQuery(), QueryBuilders.multiMatch().query(value).build()._toQuery());
    } else if (field.matches(PROPS_REGEX)) {
        qb = nestedPropsQuery(keyValueBoolQuery(field, QueryBuilders.wildcard().field(getValueFieldName(value)).value(value).build()));
    } else {
        qb = QueryBuilders.wildcard().field(field).value(value);
    }
    return qb;
}
Also used : QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant)

Example 9 with QueryVariant

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

the class ESUtils method keyValueBoolQuery.

/**
 * @param k field name
 * @param v field value
 * @param query query object
 * @return a composite query: bool(match(key) AND match(value))
 */
static QueryVariant keyValueBoolQuery(String k, String v, QueryVariant query) {
    if (StringUtils.isBlank(k) || (query == null && StringUtils.isBlank(v))) {
        return QueryBuilders.matchAll().build();
    }
    QueryVariant kQuery = QueryBuilders.match().field(PROPS_PREFIX + "k").query(b -> b.stringValue(getNestedKey(k))).operator(Operator.And).build();
    QueryVariant vQuery = (query == null) ? QueryBuilders.match().field(getValueFieldName(v)).query(b -> b.stringValue(v)).operator(Operator.And).build() : query;
    if ("*".equals(v) || query instanceof MatchAllQuery) {
        return QueryBuilders.bool().must(kQuery._toQuery()).build();
    }
    return QueryBuilders.bool().must(kQuery._toQuery(), vQuery._toQuery()).build();
}
Also used : Query(org.apache.lucene.search.Query) BulkOperation(co.elastic.clients.elasticsearch.core.bulk.BulkOperation) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Term(org.apache.lucene.index.Term) LoggerFactory(org.slf4j.LoggerFactory) TrackHits(co.elastic.clients.elasticsearch.core.search.TrackHits) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.http.Header) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) Matcher(java.util.regex.Matcher) Map(java.util.Map) FieldValue(co.elastic.clients.elasticsearch._types.FieldValue) DestroyListener(com.erudika.para.core.listeners.DestroyListener) Config(com.erudika.para.core.utils.Config) Conflicts(co.elastic.clients.elasticsearch._types.Conflicts) JsonData(co.elastic.clients.json.JsonData) ParaObject(com.erudika.para.core.ParaObject) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpEntity(org.apache.http.HttpEntity) PrefixQuery(org.apache.lucene.search.PrefixQuery) AddAction(co.elastic.clients.elasticsearch.indices.update_aliases.AddAction) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) DefaultCredentialsProvider(software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider) TypeMapping(co.elastic.clients.elasticsearch._types.mapping.TypeMapping) HttpRequest(org.apache.http.HttpRequest) WildcardQuery(org.apache.lucene.search.WildcardQuery) Objects(java.util.Objects) QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) List(java.util.List) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) ObjectBuilder(co.elastic.clients.util.ObjectBuilder) BulkResponse(co.elastic.clients.elasticsearch.core.BulkResponse) Entry(java.util.Map.Entry) Para(com.erudika.para.core.utils.Para) Pattern(java.util.regex.Pattern) HealthStatus(co.elastic.clients.elasticsearch._types.HealthStatus) QueryBuilders(co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders) NameValuePair(org.apache.http.NameValuePair) CredentialsProvider(org.apache.http.client.CredentialsProvider) JacksonJsonpMapper(co.elastic.clients.json.jackson.JacksonJsonpMapper) App(com.erudika.para.core.App) ElasticsearchAsyncClient(co.elastic.clients.elasticsearch.ElasticsearchAsyncClient) RestClientTransport(co.elastic.clients.transport.rest_client.RestClientTransport) Sysprop(com.erudika.para.core.Sysprop) RestClient(org.elasticsearch.client.RestClient) IndexAliases(co.elastic.clients.elasticsearch.indices.get_alias.IndexAliases) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) Aws4SignerParams(software.amazon.awssdk.auth.signer.params.Aws4SignerParams) HashMap(java.util.HashMap) ChildScoreMode(co.elastic.clients.elasticsearch._types.query_dsl.ChildScoreMode) Pager(com.erudika.para.core.utils.Pager) DeleteByQueryResponse(co.elastic.clients.elasticsearch.core.DeleteByQueryResponse) ArrayList(java.util.ArrayList) DeleteByQueryRequest(co.elastic.clients.elasticsearch.core.DeleteByQueryRequest) Action(co.elastic.clients.elasticsearch.indices.update_aliases.Action) DAO(com.erudika.para.core.persistence.DAO) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) LinkedList(java.util.LinkedList) Region(software.amazon.awssdk.regions.Region) BoolQuery(co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery) Property(co.elastic.clients.elasticsearch._types.mapping.Property) Refresh(co.elastic.clients.elasticsearch._types.Refresh) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) Time(co.elastic.clients.elasticsearch._types.Time) Logger(org.slf4j.Logger) SortOrder(co.elastic.clients.elasticsearch._types.SortOrder) Aws4Signer(software.amazon.awssdk.auth.signer.Aws4Signer) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser) IndexSettings(co.elastic.clients.elasticsearch.indices.IndexSettings) IOException(java.io.IOException) Utils(com.erudika.para.core.utils.Utils) BooleanClause(org.apache.lucene.search.BooleanClause) Operator(co.elastic.clients.elasticsearch._types.query_dsl.Operator) Consumer(java.util.function.Consumer) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) BooleanQuery(org.apache.lucene.search.BooleanQuery) AuthScope(org.apache.http.auth.AuthScope) HttpContext(org.apache.http.protocol.HttpContext) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) NumberUtils(org.apache.commons.lang3.math.NumberUtils) MatchAllQuery(co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery) ElasticsearchClient(co.elastic.clients.elasticsearch.ElasticsearchClient) QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant) SortOptions(co.elastic.clients.elasticsearch._types.SortOptions) RemoveAction(co.elastic.clients.elasticsearch.indices.update_aliases.RemoveAction) Collections(java.util.Collections) HttpHost(org.apache.http.HttpHost) RangeQuery(co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery) InputStream(java.io.InputStream) QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant) MatchAllQuery(co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery)

Example 10 with QueryVariant

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

the class ESUtils method prefix.

private static ObjectBuilder<?> prefix(Query q) {
    ObjectBuilder<?> qb;
    String field = ((PrefixQuery) q).getPrefix().field();
    String value = ((PrefixQuery) q).getPrefix().text();
    if (StringUtils.isBlank(field)) {
        QueryVariant kQuery = QueryBuilders.matchAll().build();
        QueryVariant vQuery = QueryBuilders.prefix().field(getValueFieldName(value)).value(value).build();
        QueryVariant nested = (QueryVariant) nestedPropsQuery(QueryBuilders.bool().must(kQuery._toQuery(), vQuery._toQuery()).build());
        qb = QueryBuilders.bool().should(nested._toQuery(), QueryBuilders.multiMatch().query(value).build()._toQuery());
    } else if (field.matches(PROPS_REGEX)) {
        qb = nestedPropsQuery(keyValueBoolQuery(field, QueryBuilders.prefix().field(getValueFieldName(value)).value(value).build()));
    } else {
        qb = QueryBuilders.prefix().field(field).value(value);
    }
    return qb;
}
Also used : QueryVariant(co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant)

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