use of org.opensearch.client.opensearch._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;
}
use of org.opensearch.client.opensearch._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();
}
}
use of org.opensearch.client.opensearch._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;
}
}
}
use of org.opensearch.client.opensearch._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());
}
Aggregations