Search in sources :

Example 1 with FieldValue

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

the class ElasticsearchAnySearchDAO method fillAttrQuery.

protected Query fillAttrQuery(final PlainSchema schema, final PlainAttrValue attrValue, final AttrCond cond) {
    Object value = schema.getType() == AttrSchemaType.Date && attrValue.getDateValue() != null ? attrValue.getDateValue().getTime() : attrValue.getValue();
    Query query = null;
    switch(cond.getType()) {
        case ISNOTNULL:
            query = new Query.Builder().exists(QueryBuilders.exists().field(schema.getKey()).build()).build();
            break;
        case ISNULL:
            query = new Query.Builder().bool(QueryBuilders.bool().mustNot(new Query.Builder().exists(QueryBuilders.exists().field(schema.getKey()).build()).build()).build()).build();
            break;
        case ILIKE:
            StringBuilder output = new StringBuilder();
            for (char c : cond.getExpression().toLowerCase().toCharArray()) {
                if (c == '%') {
                    output.append(".*");
                } else if (Character.isLetter(c)) {
                    output.append('[').append(c).append(Character.toUpperCase(c)).append(']');
                } else {
                    output.append(escapeForLikeRegex(c));
                }
            }
            query = new Query.Builder().regexp(QueryBuilders.regexp().field(schema.getKey()).value(output.toString()).build()).build();
            break;
        case LIKE:
            query = new Query.Builder().wildcard(QueryBuilders.wildcard().field(schema.getKey()).value(cond.getExpression().replace('%', '*')).build()).build();
            break;
        case IEQ:
            query = new Query.Builder().match(QueryBuilders.match().field(schema.getKey()).query(FieldValue.of(cond.getExpression().toLowerCase())).build()).build();
            break;
        case EQ:
            FieldValue fieldValue;
            if (value instanceof Double) {
                fieldValue = FieldValue.of((Double) value);
            } else if (value instanceof Long) {
                fieldValue = FieldValue.of((Long) value);
            } else if (value instanceof Boolean) {
                fieldValue = FieldValue.of((Boolean) value);
            } else {
                fieldValue = FieldValue.of(value.toString());
            }
            query = new Query.Builder().term(QueryBuilders.term().field(schema.getKey()).value(fieldValue).build()).build();
            break;
        case GE:
            query = new Query.Builder().range(QueryBuilders.range().field(schema.getKey()).gte(JsonData.of(value)).build()).build();
            break;
        case GT:
            query = new Query.Builder().range(QueryBuilders.range().field(schema.getKey()).gt(JsonData.of(value)).build()).build();
            break;
        case LE:
            query = new Query.Builder().range(QueryBuilders.range().field(schema.getKey()).lte(JsonData.of(value)).build()).build();
            break;
        case LT:
            query = new Query.Builder().range(QueryBuilders.range().field(schema.getKey()).lt(JsonData.of(value)).build()).build();
            break;
        default:
    }
    return query;
}
Also used : Query(co.elastic.clients.elasticsearch._types.query_dsl.Query) FieldValue(co.elastic.clients.elasticsearch._types.FieldValue)

Example 2 with FieldValue

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

the class TopMetrics method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    if (ApiTypeHelper.isDefined(this.sort)) {
        generator.writeKey("sort");
        generator.writeStartArray();
        for (FieldValue item0 : this.sort) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    if (ApiTypeHelper.isDefined(this.metrics)) {
        generator.writeKey("metrics");
        generator.writeStartObject();
        for (Map.Entry<String, FieldValue> item0 : this.metrics.entrySet()) {
            generator.writeKey(item0.getKey());
            item0.getValue().serialize(generator, mapper);
        }
        generator.writeEnd();
    }
}
Also used : FieldValue(org.opensearch.client.opensearch._types.FieldValue) Map(java.util.Map)

Example 3 with FieldValue

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

the class TermsQueryField method serialize.

@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
    if (_value instanceof JsonpSerializable) {
        ((JsonpSerializable) _value).serialize(generator, mapper);
    } else {
        switch(_kind) {
            case Value:
                generator.writeStartArray();
                for (FieldValue item0 : ((List<FieldValue>) this._value)) {
                    item0.serialize(generator, mapper);
                }
                generator.writeEnd();
                break;
        }
    }
}
Also used : JsonpSerializable(org.opensearch.client.json.JsonpSerializable) FieldValue(org.opensearch.client.opensearch._types.FieldValue)

Example 4 with FieldValue

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

the class BuiltinTypesTest method testFieldValue.

@Test
public void testFieldValue() {
    FieldValue f;
    f = FieldValue.of(b -> b.nullValue());
    f = checkJsonRoundtrip(f, "null");
    assertTrue(f.isNull());
    assertEquals("null", f._toJsonString());
    f = FieldValue.of(b -> b.doubleValue(1.23));
    f = checkJsonRoundtrip(f, "1.23");
    assertTrue(f.isDouble());
    assertEquals(1.23, f.doubleValue(), 0.01);
    assertEquals("1.23", f._toJsonString());
    f = FieldValue.of(b -> b.longValue(123));
    f = checkJsonRoundtrip(f, "123");
    assertTrue(f.isLong());
    assertEquals(123, f.longValue());
    assertEquals("123", f._toJsonString());
    f = FieldValue.of(b -> b.booleanValue(true));
    f = checkJsonRoundtrip(f, "true");
    assertTrue(f.isBoolean());
    assertTrue(f.booleanValue());
    assertEquals("true", f._toJsonString());
    f = FieldValue.of(b -> b.booleanValue(false));
    f = checkJsonRoundtrip(f, "false");
    assertTrue(f.isBoolean());
    assertFalse(f.booleanValue());
    assertEquals("false", f._toJsonString());
    f = FieldValue.of(b -> b.stringValue("foo"));
    f = checkJsonRoundtrip(f, "\"foo\"");
    assertTrue(f.isString());
    assertEquals("foo", f.stringValue());
    assertEquals("foo", f._toJsonString());
}
Also used : IndexSettings(org.opensearch.client.opensearch.indices.IndexSettings) List(java.util.List) FieldValue(org.opensearch.client.opensearch._types.FieldValue) SearchRequest(org.opensearch.client.opensearch.core.SearchRequest) SortOptions(org.opensearch.client.opensearch._types.SortOptions) SortOrder(org.opensearch.client.opensearch._types.SortOrder) StatsAggregate(org.opensearch.client.opensearch._types.aggregations.StatsAggregate) Test(org.junit.Test) StringStatsAggregate(org.opensearch.client.opensearch._types.aggregations.StringStatsAggregate) SpanGapQuery(org.opensearch.client.opensearch._types.query_dsl.SpanGapQuery) FieldValue(org.opensearch.client.opensearch._types.FieldValue) Test(org.junit.Test)

Aggregations

FieldValue (org.opensearch.client.opensearch._types.FieldValue)3 FieldValue (co.elastic.clients.elasticsearch._types.FieldValue)1 Query (co.elastic.clients.elasticsearch._types.query_dsl.Query)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 JsonpSerializable (org.opensearch.client.json.JsonpSerializable)1 SortOptions (org.opensearch.client.opensearch._types.SortOptions)1 SortOrder (org.opensearch.client.opensearch._types.SortOrder)1 StatsAggregate (org.opensearch.client.opensearch._types.aggregations.StatsAggregate)1 StringStatsAggregate (org.opensearch.client.opensearch._types.aggregations.StringStatsAggregate)1 SpanGapQuery (org.opensearch.client.opensearch._types.query_dsl.SpanGapQuery)1 SearchRequest (org.opensearch.client.opensearch.core.SearchRequest)1 IndexSettings (org.opensearch.client.opensearch.indices.IndexSettings)1