Search in sources :

Example 1 with SortOptions

use of co.elastic.clients.elasticsearch._types.SortOptions in project syncope by apache.

the class ElasticsearchAnySearchDAO method sortBuilders.

protected List<SortOptions> sortBuilders(final AnyTypeKind kind, final List<OrderByClause> orderBy) {
    AnyUtils anyUtils = anyUtilsFactory.getInstance(kind);
    List<SortOptions> options = new ArrayList<>();
    orderBy.forEach(clause -> {
        String sortName = null;
        // Manage difference among external key attribute and internal JPA @Id
        String fieldName = "key".equals(clause.getField()) ? "id" : clause.getField();
        Field anyField = anyUtils.getField(fieldName);
        if (anyField == null) {
            PlainSchema schema = plainSchemaDAO.find(fieldName);
            if (schema != null) {
                sortName = fieldName;
            }
        } else {
            sortName = fieldName;
        }
        if (sortName == null) {
            LOG.warn("Cannot build any valid clause from {}", clause);
        } else {
            options.add(new SortOptions.Builder().field(new FieldSort.Builder().field(sortName).order(clause.getDirection() == OrderByClause.Direction.ASC ? SortOrder.Asc : SortOrder.Desc).build()).build());
        }
    });
    return options;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) SortOptions(co.elastic.clients.elasticsearch._types.SortOptions)

Example 2 with SortOptions

use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.

the class SearchRequest method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    if (this.source != null) {
        generator.writeKey("_source");
        this.source.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.aggregations)) {
        generator.writeKey("aggregations");
        generator.writeStartObject();
        for (Map.Entry<String, Aggregation> item0 : this.aggregations.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (this.collapse != null) {
        generator.writeKey("collapse");
        this.collapse.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.docvalueFields)) {
        generator.writeKey("docvalue_fields");
        generator.writeStartArray();
        for (FieldAndFormat item0 : this.docvalueFields) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (this.explain != null) {
        generator.writeKey("explain");
        generator.write(this.explain);
    }
    if (ApiTypeHelper.isDefined(this.fields)) {
        generator.writeKey("fields");
        generator.writeStartArray();
        for (FieldAndFormat item0 : this.fields) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (this.from != null) {
        generator.writeKey("from");
        generator.write(this.from);
    }
    if (this.highlight != null) {
        generator.writeKey("highlight");
        this.highlight.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.indicesBoost)) {
        generator.writeKey("indices_boost");
        generator.writeStartArray();
        for (Map<String, Double> item0 : this.indicesBoost) {
            generator.writeStartObject();
            if (item0 != null) {
                for (Map.Entry<String, Double> item1 : item0.entrySet()) {
                    generator.writeKey(item1.getKey());
                    generator.write(item1.getValue());
                }
            }
            generator.writeEnd();
        }
        generator.writeEnd();
    }
    if (this.minScore != null) {
        generator.writeKey("min_score");
        generator.write(this.minScore);
    }
    if (this.postFilter != null) {
        generator.writeKey("post_filter");
        this.postFilter.serialize(generator, mapper);
    }
    if (this.profile != null) {
        generator.writeKey("profile");
        generator.write(this.profile);
    }
    if (this.query != null) {
        generator.writeKey("query");
        this.query.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.rescore)) {
        generator.writeKey("rescore");
        generator.writeStartArray();
        for (Rescore item0 : this.rescore) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.runtimeMappings)) {
        generator.writeKey("runtime_mappings");
        generator.writeStartObject();
        for (Map.Entry<String, RuntimeField> item0 : this.runtimeMappings.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.scriptFields)) {
        generator.writeKey("script_fields");
        generator.writeStartObject();
        for (Map.Entry<String, ScriptField> item0 : this.scriptFields.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.searchAfter)) {
        generator.writeKey("search_after");
        generator.writeStartArray();
        for (String item0 : this.searchAfter) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (this.seqNoPrimaryTerm != null) {
        generator.writeKey("seq_no_primary_term");
        generator.write(this.seqNoPrimaryTerm);
    }
    if (this.size != null) {
        generator.writeKey("size");
        generator.write(this.size);
    }
    if (this.slice != null) {
        generator.writeKey("slice");
        this.slice.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.sort)) {
        generator.writeKey("sort");
        generator.writeStartArray();
        for (SortOptions item0 : this.sort) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.stats)) {
        generator.writeKey("stats");
        generator.writeStartArray();
        for (String item0 : this.stats) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.storedFields)) {
        generator.writeKey("stored_fields");
        generator.writeStartArray();
        for (String item0 : this.storedFields) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (this.suggest != null) {
        generator.writeKey("suggest");
        this.suggest.serialize(generator, mapper);
    }
    if (this.terminateAfter != null) {
        generator.writeKey("terminate_after");
        generator.write(this.terminateAfter);
    }
    if (this.timeout != null) {
        generator.writeKey("timeout");
        generator.write(this.timeout);
    }
    if (this.trackScores != null) {
        generator.writeKey("track_scores");
        generator.write(this.trackScores);
    }
    if (this.trackTotalHits != null) {
        generator.writeKey("track_total_hits");
        this.trackTotalHits.serialize(generator, mapper);
    }
    if (this.version != null) {
        generator.writeKey("version");
        generator.write(this.version);
    }
}
Also used : Rescore(org.opensearch.client.opensearch.core.search.Rescore) RuntimeField(org.opensearch.client.opensearch._types.mapping.RuntimeField) FieldAndFormat(org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat) Aggregation(org.opensearch.client.opensearch._types.aggregations.Aggregation) ScriptField(org.opensearch.client.opensearch._types.ScriptField) HashMap(java.util.HashMap) Map(java.util.Map) SortOptions(org.opensearch.client.opensearch._types.SortOptions)

Example 3 with SortOptions

use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.

the class Source method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    if (ApiTypeHelper.isDefined(this.index)) {
        generator.writeKey("index");
        generator.writeStartArray();
        for (String item0 : this.index) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (this.query != null) {
        generator.writeKey("query");
        this.query.serialize(generator, mapper);
    }
    if (this.remote != null) {
        generator.writeKey("remote");
        this.remote.serialize(generator, mapper);
    }
    if (this.size != null) {
        generator.writeKey("size");
        generator.write(this.size);
    }
    if (this.slice != null) {
        generator.writeKey("slice");
        this.slice.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.sort)) {
        generator.writeKey("sort");
        generator.writeStartArray();
        for (SortOptions item0 : this.sort) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.sourceFields)) {
        generator.writeKey("_source");
        generator.writeStartArray();
        for (String item0 : this.sourceFields) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.runtimeMappings)) {
        generator.writeKey("runtime_mappings");
        generator.writeStartObject();
        for (Map.Entry<String, RuntimeField> item0 : this.runtimeMappings.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
}
Also used : RuntimeField(org.opensearch.client.opensearch._types.mapping.RuntimeField) Map(java.util.Map) SortOptions(org.opensearch.client.opensearch._types.SortOptions)

Example 4 with SortOptions

use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.

the class TopHitsAggregation method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    super.serializeInternal(generator, mapper);
    if (ApiTypeHelper.isDefined(this.docvalueFields)) {
        generator.writeKey("docvalue_fields");
        generator.writeStartArray();
        for (String item0 : this.docvalueFields) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (this.explain != null) {
        generator.writeKey("explain");
        generator.write(this.explain);
    }
    if (this.from != null) {
        generator.writeKey("from");
        generator.write(this.from);
    }
    if (this.highlight != null) {
        generator.writeKey("highlight");
        this.highlight.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.scriptFields)) {
        generator.writeKey("script_fields");
        generator.writeStartObject();
        for (Map.Entry<String, ScriptField> item0 : this.scriptFields.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (this.size != null) {
        generator.writeKey("size");
        generator.write(this.size);
    }
    if (ApiTypeHelper.isDefined(this.sort)) {
        generator.writeKey("sort");
        generator.writeStartArray();
        for (SortOptions item0 : this.sort) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (this.source != null) {
        generator.writeKey("_source");
        this.source.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.storedFields)) {
        generator.writeKey("stored_fields");
        generator.writeStartArray();
        for (String item0 : this.storedFields) {
            generator.write(item0);
        }
        generator.writeEnd();
    }
    if (this.trackScores != null) {
        generator.writeKey("track_scores");
        generator.write(this.trackScores);
    }
    if (this.version != null) {
        generator.writeKey("version");
        generator.write(this.version);
    }
    if (this.seqNoPrimaryTerm != null) {
        generator.writeKey("seq_no_primary_term");
        generator.write(this.seqNoPrimaryTerm);
    }
}
Also used : ScriptField(org.opensearch.client.opensearch._types.ScriptField) Map(java.util.Map) SortOptions(org.opensearch.client.opensearch._types.SortOptions)

Example 5 with SortOptions

use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.

the class BucketSortAggregation method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    super.serializeInternal(generator, mapper);
    if (this.from != null) {
        generator.writeKey("from");
        generator.write(this.from);
    }
    if (this.gapPolicy != null) {
        generator.writeKey("gap_policy");
        this.gapPolicy.serialize(generator, mapper);
    }
    if (this.size != null) {
        generator.writeKey("size");
        generator.write(this.size);
    }
    if (ApiTypeHelper.isDefined(this.sort)) {
        generator.writeKey("sort");
        generator.writeStartArray();
        for (SortOptions item0 : this.sort) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
}
Also used : SortOptions(org.opensearch.client.opensearch._types.SortOptions)

Aggregations

SortOptions (org.opensearch.client.opensearch._types.SortOptions)7 Map (java.util.Map)4 ScriptField (org.opensearch.client.opensearch._types.ScriptField)3 RuntimeField (org.opensearch.client.opensearch._types.mapping.RuntimeField)2 FieldAndFormat (org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat)2 SortOptions (co.elastic.clients.elasticsearch._types.SortOptions)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)1 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)1 Test (org.junit.Test)1 Aggregation (org.opensearch.client.opensearch._types.aggregations.Aggregation)1 Rescore (org.opensearch.client.opensearch.core.search.Rescore)1