/** * @return the identifier of the ElasticSearch type (including it's index name), that corresponds to a certain document type */ private static IndexType getAuthorizationIndexType(IndexType indexType) { requireNonNull(indexType); requireNonNull(indexType.getIndex()); checkArgument(!TYPE_AUTHORIZATION.equals(indexType.getType()), "Authorization types do not have authorization on their own."); return new IndexType(indexType.getIndex(), TYPE_AUTHORIZATION); }
private static String initializedId(IndexType indexType) { return indexType.getIndex() + "." + indexType.getType() + ".initialized"; }
DocId(IndexType indexType, String id) { this(indexType.getIndex(), indexType.getType(), id); }
private List<String> loadExistingIndicesExceptMetadata(Collection<Index> definitions) { Set<String> definedNames = definitions.stream().map(IndexDefinition.Index::getName).collect(Collectors.toSet()); return Arrays.stream(client.nativeClient().admin().indices().prepareGetIndex().get().getIndices()) .filter(definedNames::contains) .filter(index -> !MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex().equals(index)) .collect(Collectors.toList()); } }
private void setInitialized(IndexType indexType) { String index = indexType.getIndex(); waitForIndexYellow(index); metadataIndex.setInitialized(indexType, true); }
private static void updateSettings(BulkIndexer bulkIndexer, Map<String, Object> settings) { UpdateSettingsRequestBuilder req = bulkIndexer.client.nativeClient().admin().indices().prepareUpdateSettings(bulkIndexer.indexType.getIndex()); req.setSettings(settings); req.get(); } }
@Override void afterStop(BulkIndexer bulkIndexer) { // optimize lucene segments and revert index settings // Optimization must be done before re-applying replicas: // http://www.elasticsearch.org/blog/performance-considerations-elasticsearch-indexing/ bulkIndexer.client.prepareForceMerge(bulkIndexer.indexType.getIndex()).get(); updateSettings(bulkIndexer, initialSettings); this.progress.stop(); }
/** * Completely remove a index with all types */ public void clearIndex(IndexType indexType) { BulkIndexer.delete(esClient, indexType, esClient.prepareSearch(indexType.getIndex()).setQuery(matchAllQuery())); }
@Test public void test_getAuthorizationScope() { AuthorizationScope scope = underTest.getAuthorizationScope(); assertThat(scope.getIndexType().getIndex()).isEqualTo(INDEX_TYPE_ISSUE.getIndex()); assertThat(scope.getIndexType().getType()).isEqualTo(TYPE_AUTHORIZATION); Predicate<IndexPermissions> projectPredicate = scope.getProjectPredicate(); IndexPermissions project = new IndexPermissions("P1", Qualifiers.PROJECT); IndexPermissions file = new IndexPermissions("F1", Qualifiers.FILE); assertThat(projectPredicate.test(project)).isTrue(); assertThat(projectPredicate.test(file)).isFalse(); }
private static IndexRequest newIndexRequest(ViewDoc doc) { return new IndexRequest(ViewIndexDefinition.INDEX_TYPE_VIEW.getIndex(), ViewIndexDefinition.INDEX_TYPE_VIEW.getType(), doc.uuid()) .source(doc.getFields()); }
public IndexRequestBuilder prepareIndex(IndexType indexType) { return new ProxyIndexRequestBuilder(nativeClient()).setIndex(indexType.getIndex()).setType(indexType.getType()); }
public GetRequestBuilder prepareGet(IndexType indexType, String id) { return new ProxyGetRequestBuilder(nativeClient()).setIndex(indexType.getIndex()).setType(indexType.getType()).setId(id); }
private static IndexRequest newIndexRequest(ProjectMeasuresDoc doc) { String projectUuid = doc.getId(); return new IndexRequest(INDEX_TYPE_PROJECT_MEASURES.getIndex(), INDEX_TYPE_PROJECT_MEASURES.getType(), projectUuid) .routing(projectUuid) .parent(projectUuid) .source(doc.getFields()); }
private List<AnalyzeResponse.AnalyzeToken> analyzeIndexedTokens(String text) { return tester.client().nativeClient().admin().indices().prepareAnalyze(INDEX_TYPE_RULE.getIndex(), text) .setField(ENGLISH_HTML_ANALYZER.subField(FIELD_RULE_HTML_DESCRIPTION)) .execute().actionGet().getTokens(); } }
private static IndexRequest newRuleDocIndexRequest(RuleForIndexingDto ruleForIndexingDto) { RuleDoc doc = RuleDoc.of(ruleForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE.getIndex(), INDEX_TYPE_RULE.getType()) .id(doc.getId()) .routing(doc.getRouting()) .source(doc.getFields()); }
private static IndexRequest newIndexRequest(ComponentDoc doc) { return new IndexRequest(INDEX_TYPE_COMPONENT.getIndex(), INDEX_TYPE_COMPONENT.getType(), doc.getId()) .routing(doc.getRouting()) .parent(doc.getParent()) .source(doc.getFields()); }
private static IndexRequest newRuleExtensionDocIndexRequest(RuleForIndexingDto ruleForIndexingDto) { RuleExtensionDoc ruleExtensionDoc = RuleExtensionDoc.of(ruleForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType()) .id(ruleExtensionDoc.getId()) .routing(ruleExtensionDoc.getRouting()) .parent(ruleExtensionDoc.getParent()) .source(ruleExtensionDoc.getFields()); }
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(); } }
private static IndexRequest newRuleExtensionDocIndexRequest(RuleExtensionForIndexingDto ruleExtensionForIndexingDto) { RuleExtensionDoc doc = RuleExtensionDoc.of(ruleExtensionForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType()) .id(doc.getId()) .routing(doc.getRouting()) .parent(doc.getParent()) .source(doc.getFields()); }
@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(); } }