/** * Creates a type that requires to verify that user has the read permission * when searching for documents. * * Both types {@code typeName} and "authorization" are created. Documents * must be created with _parent and _routing having the parent uuid as values. * * @see NewIndex.NewIndexType#requireProjectAuthorization() */ private static NewIndex.NewIndexType enableProjectAuthorization(NewIndex.NewIndexType type) { type.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION)); type.setAttribute("_routing", ImmutableMap.of("required", true)); NewIndex.NewIndexType authType = type.getIndex().createType(TYPE_AUTHORIZATION); authType.setAttribute("_routing", ImmutableMap.of("required", true)); authType.createLongField(FIELD_GROUP_IDS); authType.createLongField(FIELD_USER_IDS); authType.createBooleanField(FIELD_ALLOW_ANYONE); authType.setEnableSource(false); return type; }
@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"); }
@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 mark_all_non_existing_index_types_as_uninitialized() { startNewCreator(context -> { NewIndex i = context.create("fakes", SETTINGS_CONFIGURATION); i.createType("t1"); i.createType("t2"); }); assertThat(metadataIndex.getHash("fakes")).isNotEmpty(); assertThat(metadataIndex.getInitialized(new IndexType("fakes", "t1"))).isFalse(); assertThat(metadataIndex.getInitialized(new IndexType("fakes", "t2"))).isFalse(); }
@Test public void index_without_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(false); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", false)); }
@Test public void index_with_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(true); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", true)); }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create("fakes", SETTINGS_CONFIGURATION); NewIndex.NewIndexType mapping = index.createType("fake"); mapping.keywordFieldBuilder("key").build(); mapping.createDateTimeField("updatedAt"); } }
public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_METADATA.getIndex(), newBuilder(configuration) .setRefreshInterval(MANUAL_REFRESH_INTERVAL) .setDefaultNbOfShards(DEFAULT_NUMBER_OF_SHARDS) .build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_METADATA.getType()); mapping.keywordFieldBuilder(FIELD_VALUE).disableSearch().store().build(); } }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create("fakes", SETTINGS_CONFIGURATION); NewIndex.NewIndexType mapping = index.createType("fake"); mapping.keywordFieldBuilder("key").build(); mapping.createDateTimeField("updatedAt"); mapping.createIntegerField("newField"); } }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create(INDEX, newBuilder(new MapSettings().asConfig()).build()); index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas); index.getSettings().put("index.refresh_interval", "-1"); NewIndex.NewIndexType type = index.createType(INDEX_TYPE_FAKE.getType()); type.createIntegerField(INT_FIELD); }
@Test public void index_requires_project_authorization() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); index.createType("issue") // creates a second type "authorization" and configures _parent and _routing fields .requireProjectAuthorization(); // issue type NewIndex.NewIndexType issueType = index.getTypes().get("issue"); assertThat(getAttributeAsMap(issueType, "_parent")).containsExactly(entry("type", "authorization")); assertThat(getAttributeAsMap(issueType, "_routing")).containsExactly(entry("required", true)); // authorization type NewIndex.NewIndexType authorizationType = index.getTypes().get("authorization"); assertThat(getAttributeAsMap(authorizationType, "_parent")).isNull(); assertThat(getAttributeAsMap(authorizationType, "_routing")).containsExactly(entry("required", true)); }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_VIEW.getIndex(), newBuilder(config) .setDefaultNbOfShards(5) .build()); // type "view" NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_VIEW.getType()); mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_PROJECTS).disableNorms().build(); } }
@Test public void fail_when_nested_with_no_field() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("At least one sub-field must be declared in nested property 'measures'"); NewIndex index = new NewIndex("projectmeasures", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("project_measures"); mapping.nestedFieldBuilder("measures").build(); }
@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(); }
private NewIndex createIndex() { NewIndex newIndex = new NewIndex("fakes", newBuilder(new MapSettings().asConfig()).build()); NewIndex.NewIndexType mapping = newIndex.createType("fake"); mapping.setAttribute("list_attr", Arrays.asList("foo", "bar")); mapping.keywordFieldBuilder("key").build(); mapping.createDateTimeField("updatedAt"); return newIndex; }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_TEST.getIndex(), newBuilder(config) .setRefreshInterval(MANUAL_REFRESH_INTERVAL) .setDefaultNbOfShards(5) .build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType()); mapping.setAttribute("_routing", ImmutableMap.of("required", true)); mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build(); mapping.createLongField(FIELD_DURATION_IN_MS); mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of( FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", INDEX_SEARCHABLE), FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer")))); mapping.createDateTimeField(FIELD_UPDATED_AT); } }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create(FOO_INDEX, newBuilder(new MapSettings().asConfig()).setRefreshInterval(MANUAL_REFRESH_INTERVAL).build()); NewIndex.NewIndexType type = index.createType(FOO_TYPE) .requireProjectAuthorization(); type.keywordFieldBuilder(FIELD_NAME).build(); type.keywordFieldBuilder(FIELD_PROJECT_UUID).build(); } }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create(INDEX_TYPE_USER.getIndex(), newBuilder(config) .setDefaultNbOfShards(1) .build()); // type "user" NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType()); mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build(); mapping.createBooleanField(FIELD_ACTIVE); mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build(); } }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_COMPONENT.getIndex(), newBuilder(config) .setRefreshInterval(MANUAL_REFRESH_INTERVAL) .setDefaultNbOfShards(DEFAULT_NUMBER_OF_SHARDS) .build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_COMPONENT.getType()) .requireProjectAuthorization(); mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build(); mapping.textFieldBuilder(FIELD_NAME) .withFieldData() .termVectorWithPositionOffsets() .addSubFields(NAME_ANALYZERS) .build(); mapping.keywordFieldBuilder(FIELD_QUALIFIER).build(); mapping.keywordFieldBuilder(FIELD_LANGUAGE).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).disableNorms().build(); } }
.build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType()) .requireProjectAuthorization();