Search in sources :

Example 1 with TypeMapping

use of org.opensearch.client.opensearch._types.mapping.TypeMapping in project opensearch-java by opensearch-project.

the class VariantsTest method testNestedTaggedUnionWithDefaultTag.

@Test
public void testNestedTaggedUnionWithDefaultTag() {
    // Object fields don't really exist in ES and are based on a naming convention where field names
    // are dot-separated paths. The hierarchy is rebuilt from these names and ES doesn't send back
    // "type": "object" for object properties.
    // 
    // Mappings are therefore a hierarchy of internally-tagged unions based on the "type" property
    // with a default "object" tag value if the "type" property is missing.
    String json = "{\n" + "  \"testindex\" : {\n" + "    \"mappings\" : {\n" + "      \"properties\" : {\n" + "        \"id\" : {\n" + "          \"type\" : \"text\",\n" + "          \"fields\" : {\n" + "            \"keyword\" : {\n" + "              \"type\" : \"keyword\",\n" + "              \"ignore_above\" : 256\n" + "            }\n" + "          }\n" + "        },\n" + "        \"name\" : {\n" + "          \"properties\" : {\n" + "            \"first\" : {\n" + "              \"type\" : \"text\",\n" + "              \"fields\" : {\n" + "                \"keyword\" : {\n" + "                  \"type\" : \"keyword\",\n" + "                  \"ignore_above\" : 256\n" + "                }\n" + "              }\n" + "            },\n" + "            \"last\" : {\n" + "              \"type\" : \"text\",\n" + "              \"fields\" : {\n" + "                \"keyword\" : {\n" + "                  \"type\" : \"keyword\",\n" + "                  \"ignore_above\" : 256\n" + "                }\n" + "              }\n" + "            }\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    GetMappingResponse response = fromJson(json, GetMappingResponse.class);
    TypeMapping mappings = response.get("testindex").mappings();
    assertTrue(mappings.properties().get("name").isObject());
    assertEquals(256, mappings.properties().get("name").object().properties().get("first").text().fields().get("keyword").keyword().ignoreAbove().longValue());
    assertTrue(mappings.properties().get("id").isText());
    assertEquals(256, mappings.properties().get("id").text().fields().get("keyword").keyword().ignoreAbove().longValue());
}
Also used : GetMappingResponse(org.opensearch.client.opensearch.indices.GetMappingResponse) TypeMapping(org.opensearch.client.opensearch._types.mapping.TypeMapping) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 TypeMapping (org.opensearch.client.opensearch._types.mapping.TypeMapping)1 GetMappingResponse (org.opensearch.client.opensearch.indices.GetMappingResponse)1