@Test public void define_nested_field() { NewIndex index = new NewIndex("projectmeasures", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("projectmeasures"); mapping.nestedFieldBuilder("measures") .addKeywordField("key") .addDoubleField("value") .build(); Map<String, Object> result = (Map) mapping.getProperty("measures"); assertThat(result.get("type")).isEqualTo("nested"); Map<String, Map<String, Object>> subProperties = (Map) result.get("properties"); assertThat(subProperties.get("key").get("type")).isEqualTo("keyword"); assertThat(subProperties.get("value").get("type")).isEqualTo("double"); }
@Test public void use_doc_values_by_default() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.keywordFieldBuilder("the_doc_value").build(); Map<String, Object> props = (Map) mapping.getProperty("the_doc_value"); assertThat(props.get("type")).isEqualTo("keyword"); assertThat(props.get("doc_values")).isEqualTo("true"); }
.build(); Map<String, Object> props = (Map) mapping.getProperty("basic_field"); assertThat(props.get("type")).isEqualTo("keyword"); assertThat(props.get("index")).isEqualTo("true"); assertThat(props.get("fields")).isNull(); props = (Map) mapping.getProperty("not_searchable_field"); assertThat(props.get("type")).isEqualTo("keyword"); assertThat(props.get("index")).isEqualTo("false"); assertThat(props.get("fields")).isNull(); props = (Map) mapping.getProperty("all_capabilities_field"); assertThat(props.get("type")).isEqualTo("keyword"); props = (Map) mapping.getProperty("dumb_text_storage"); assertThat(props.get("type")).isEqualTo("keyword"); assertThat(props.get("index")).isEqualTo("false");
@Test public void define_fields() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setAttribute("dynamic", "true"); mapping.setProperty("foo_field", ImmutableMap.of("type", "keyword")); mapping.createBooleanField("boolean_field"); mapping.createByteField("byte_field"); mapping.createDateTimeField("dt_field"); mapping.createDoubleField("double_field"); mapping.createIntegerField("int_field"); mapping.createLongField("long_field"); mapping.createShortField("short_field"); mapping.createUuidPathField("uuid_path_field"); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(mapping.getAttributes().get("dynamic")).isEqualTo("true"); assertThat(mapping.getProperty("foo_field")).isInstanceOf(Map.class); assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "keyword"); assertThat((Map) mapping.getProperty("byte_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("double_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("dt_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("int_field")).containsEntry("type", "integer"); assertThat((Map) mapping.getProperty("long_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("short_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("uuid_path_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("unknown")).isNull(); }