use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.
the class TopMetricsAggregation method serializeInternal.
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
super.serializeInternal(generator, mapper);
if (ApiTypeHelper.isDefined(this.metrics)) {
generator.writeKey("metrics");
generator.writeStartArray();
for (TopMetricsValue item0 : this.metrics) {
item0.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();
}
}
use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.
the class BuiltinTypesTest method testSortOptions.
@Test
public void testSortOptions() {
// Has a custom deserializer
String json;
SortOptions sort;
// Arbitrary field
sort = fromJson("{ \"post_date\" : {\"order\" : \"asc\", \"format\": \"strict_date_optional_time_nanos\"}}", SortOptions.class);
assertEquals("post_date", sort.field().field());
assertEquals(SortOrder.Asc, sort.field().order());
sort = fromJson("{\n" + " \"offer.price\" : {\n" + " \"mode\" : \"avg\",\n" + " \"order\" : \"asc\",\n" + " \"nested\": {\n" + " \"path\": \"offer\",\n" + " \"filter\": {\n" + " \"term\" : { \"offer.color\" : \"blue\" }\n" + " }\n" + " }\n" + " }\n" + " }", SortOptions.class);
assertEquals("blue", sort.field().nested().filter().term().value().stringValue());
// Geo distance
sort = fromJson("{\n" + " \"_geo_distance\" : {\n" + " \"pin.location\" : {\n" + " \"lat\" : 40,\n" + " \"lon\" : -70\n" + " },\n" + " \"order\" : \"asc\",\n" + " \"unit\" : \"km\"\n" + " }\n" + " }", SortOptions.class);
assertEquals(40, sort.geoDistance().location().get(0).latlon().lat(), 0.1);
// Simple string shortcuts
sort = fromJson("\"user\"", SortOptions.class);
assertEquals("user", sort.field().field());
sort = fromJson("\"_doc\"", SortOptions.class);
assertTrue(sort.isDoc());
sort = fromJson("\"_score\"", SortOptions.class);
assertTrue(sort.isScore());
}
use of co.elastic.clients.elasticsearch._types.SortOptions in project opensearch-java by opensearch-project.
the class InnerHits method serializeInternal.
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (this.name != null) {
generator.writeKey("name");
generator.write(this.name);
}
if (this.size != null) {
generator.writeKey("size");
generator.write(this.size);
}
if (this.from != null) {
generator.writeKey("from");
generator.write(this.from);
}
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 (this.highlight != null) {
generator.writeKey("highlight");
this.highlight.serialize(generator, mapper);
}
if (this.ignoreUnmapped != null) {
generator.writeKey("ignore_unmapped");
generator.write(this.ignoreUnmapped);
}
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.seqNoPrimaryTerm != null) {
generator.writeKey("seq_no_primary_term");
generator.write(this.seqNoPrimaryTerm);
}
if (ApiTypeHelper.isDefined(this.fields)) {
generator.writeKey("fields");
generator.writeStartArray();
for (String item0 : this.fields) {
generator.write(item0);
}
generator.writeEnd();
}
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.storedField)) {
generator.writeKey("stored_field");
generator.writeStartArray();
for (String item0 : this.storedField) {
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);
}
}
Aggregations