Search in sources :

Example 1 with JsonData

use of org.opensearch.client.json.JsonData in project opensearch-java by opensearch-project.

the class PercolateQuery method serializeInternal.

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
    super.serializeInternal(generator, mapper);
    if (this.document != null) {
        generator.writeKey("document");
        this.document.serialize(generator, mapper);
    }
    if (ApiTypeHelper.isDefined(this.documents)) {
        generator.writeKey("documents");
        generator.writeStartArray();
        for (JsonData item0 : this.documents) {
            item0.serialize(generator, mapper);
        }
        generator.writeEnd();
    }
    generator.writeKey("field");
    generator.write(this.field);
    if (this.id != null) {
        generator.writeKey("id");
        generator.write(this.id);
    }
    if (this.index != null) {
        generator.writeKey("index");
        generator.write(this.index);
    }
    if (this.name != null) {
        generator.writeKey("name");
        generator.write(this.name);
    }
    if (this.preference != null) {
        generator.writeKey("preference");
        generator.write(this.preference);
    }
    if (this.routing != null) {
        generator.writeKey("routing");
        generator.write(this.routing);
    }
    if (this.version != null) {
        generator.writeKey("version");
        generator.write(this.version);
    }
}
Also used : JsonData(org.opensearch.client.json.JsonData)

Example 2 with JsonData

use of org.opensearch.client.json.JsonData in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterGetSettings.

public void testClusterGetSettings() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    final String transientSettingValue = "10b";
    final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Map<String, JsonData> transientSettingsMap = new HashMap<>();
    Map<String, JsonData> persistentSettingsMap = new HashMap<>();
    transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
    persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
    PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
    openSearchClient.cluster().putSettings(request);
    GetClusterSettingsResponse getSettingsResponse = openSearchClient.cluster().getSettings(new GetClusterSettingsRequest.Builder().build());
    assertEquals(1, getSettingsResponse.persistent().size());
    assertEquals(1, getSettingsResponse.transient_().size());
    assertEquals(0, getSettingsResponse.defaults().size());
}
Also used : GetClusterSettingsResponse(org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse) HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) JsonData(org.opensearch.client.json.JsonData)

Example 3 with JsonData

use of org.opensearch.client.json.JsonData in project opensearch-java by opensearch-project.

the class JsonDataTest method testParsing.

@Test
public void testParsing() {
    JsonpMapper mapper = new JsonbJsonpMapper();
    String json = "{\"children\":[{\"doubleValue\":3.2,\"intValue\":2}],\"doubleValue\":2.1,\"intValue\":1," + "\"stringValue\":\"foo\"}";
    JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
    JsonData data = JsonData.from(parser, mapper);
    assertEquals("foo", data.toJson().asJsonObject().getString("stringValue"));
    JsonpMapperTest.SomeClass to = data.to(JsonpMapperTest.SomeClass.class);
    assertEquals("foo", to.getStringValue());
}
Also used : JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonpMapper(org.opensearch.client.json.JsonpMapper) StringReader(java.io.StringReader) JsonbJsonpMapper(org.opensearch.client.json.jsonb.JsonbJsonpMapper) JsonString(jakarta.json.JsonString) JsonData(org.opensearch.client.json.JsonData) JsonParser(jakarta.json.stream.JsonParser) Test(org.junit.Test)

Example 4 with JsonData

use of org.opensearch.client.json.JsonData in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterPutSettings.

public void testClusterPutSettings() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    String[] transientSettingKeySplit = transientSettingKey.split("\\.");
    final String transientSettingValue = "10b";
    final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    String[] persistentSettingKeySplit = persistentSettingKey.split("\\.");
    final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Map<String, JsonData> transientSettingsMap = new HashMap<>();
    Map<String, JsonData> persistentSettingsMap = new HashMap<>();
    transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
    persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
    PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
    PutClusterSettingsResponse response = openSearchClient.cluster().putSettings(request);
    assertTrue(response.acknowledged());
    assertThat(response.transient_().get(transientSettingKeySplit[0]), notNullValue());
    assertThat(response.transient_().get(persistentSettingKeySplit[0]), nullValue());
    assertEquals(response.transient_().get(transientSettingKeySplit[0]).toJson().asJsonObject().getJsonObject("recovery").getString("max_bytes_per_sec"), transientSettingValue);
    assertThat(response.persistent().get(transientSettingKeySplit[0]), nullValue());
    assertThat(response.persistent().get(persistentSettingKeySplit[0]), notNullValue());
    assertEquals(response.persistent().get(persistentSettingKeySplit[0]).toJson().asJsonObject().getJsonObject("routing").getJsonObject("allocation").getString("enable"), persistentSettingValue);
}
Also used : HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) PutClusterSettingsResponse(org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse) JsonData(org.opensearch.client.json.JsonData)

Example 5 with JsonData

use of org.opensearch.client.json.JsonData in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterUpdateSettingNonExistent.

public void testClusterUpdateSettingNonExistent() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    String setting = "no_idea_what_you_are_talking_about";
    int value = 10;
    Map<String, JsonData> transientSettingsMap = new HashMap<>();
    transientSettingsMap.put(setting, JsonData.of(value));
    PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().transient_(transientSettingsMap).build();
    try {
        openSearchClient.cluster().putSettings(request);
        fail();
    } catch (OpenSearchException e) {
        assertNotNull(e);
        assertEquals(e.response().status(), 400);
        assertEquals(e.getMessage(), "Request failed: [illegal_argument_exception] " + "transient setting [no_idea_what_you_are_talking_about], not recognized");
    }
}
Also used : HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchException(org.opensearch.client.opensearch._types.OpenSearchException) JsonData(org.opensearch.client.json.JsonData)

Aggregations

JsonData (org.opensearch.client.json.JsonData)9 HashMap (java.util.HashMap)4 OpenSearchClient (org.opensearch.client.opensearch.OpenSearchClient)4 PutClusterSettingsRequest (org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest)4 Test (org.junit.Test)3 JsonbJsonpMapper (org.opensearch.client.json.jsonb.JsonbJsonpMapper)3 JsonString (jakarta.json.JsonString)2 JsonParser (jakarta.json.stream.JsonParser)2 StringReader (java.io.StringReader)2 JsonpMapper (org.opensearch.client.json.JsonpMapper)2 GetClusterSettingsResponse (org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse)2 JsonValue (jakarta.json.JsonValue)1 JsonGenerator (jakarta.json.stream.JsonGenerator)1 StringWriter (java.io.StringWriter)1 OpenSearchException (org.opensearch.client.opensearch._types.OpenSearchException)1 GetClusterSettingsRequest (org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest)1 PutClusterSettingsResponse (org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse)1