Skip to content

Commit

Permalink
test range query JsonData type value
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Nov 18, 2024
1 parent 599de04 commit 7ef8720
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;
import org.opensearch.client.opensearch.IOUtils;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class JsonpMapperTest extends Assert {
Expand Down Expand Up @@ -240,4 +242,29 @@ public void setChildren(List<SomeClass> children) {
this.children = children;
}
}

@Test
public void testRangeQuery() {

String expectedStringValue =
"{\"aggregations\":{},\"query\":{\"range\":{\"rangeField\":{\"gte\":10.5,\"lte\":30,\"from\":\"2024-01-01T00:00:00Z\",\"format\":\"strict_date_optional_time\"}}},\"terminate_after\":5}";

SearchRequest searchRequest = SearchRequest.of(
request -> request.index("index1", "index2")
.aggregations(Collections.emptyMap())
.terminateAfter(5L)
.query(
q -> q.range(
r -> r.field("rangeField")
.gte(JsonData.of(10.5))
.lte(JsonData.of(30))
.from(JsonData.of("2024-01-01T00:00:00Z"))
.format("strict_date_optional_time")
)
)
);
String searchRequestString = searchRequest.toJsonString();
assertEquals(expectedStringValue, searchRequestString);
}

}

0 comments on commit 7ef8720

Please sign in to comment.