public EntityIndex load( IndexLocationStrategy locationStrategy ) { EntityIndex index = new EsEntityIndexImpl( provider, indexCache, config, metricsFactory, locationStrategy ); index.initialize(); return index; } } );
/** * if there are aliases then we must have an index...weak knowledge * @return */ private boolean shouldInitialize() { String[] writes = getIndexes(AliasType.Write); return writes.length==0; }
final QueryVisitor visitor = visitParsedQuery(parsedQuery); return buildCandidateResultsForDirectQuery(directIdentifiers, parsedQuery, searchTypes); long totalEdgeSizeInBytes; if (totalEdgeSizeFromCache == null){ totalEdgeSizeInBytes = getTotalEntitySizeInBytes(searchEdge); sizeCache.put(cacheKey, totalEdgeSizeInBytes); }else{ long totalIndexSizeInBytes; if (totalIndexSizeFromCache == null){ totalIndexSizeInBytes = getIndexSize(); sizeCache.put(indexLocationStrategy.getIndexRootName(), totalIndexSizeInBytes); }else{ return parseResults( searchResponse, parsedQuery, limit, offset, hasGeoSortPredicates);
createMappings( indexName ); addAlias(indexName); testNewIndex();
@Override public void initialize() { final int numberOfShards = indexLocationStrategy.getNumberOfShards(); final int numberOfReplicas = indexLocationStrategy.getNumberOfReplicas(); aliasCache.invalidate(alias); if (shouldInitialize()) { addIndex( indexLocationStrategy.getIndexInitialName(), numberOfShards, numberOfReplicas, indexFig.getWriteConsistencyLevel() ); } }
@Override public long getTotalEntitySizeInBytes(final SearchEdge edge){ //"term":{"edgeName":"zzzcollzzz|roles"} SearchRequestBuilder builder = searchRequestBuilderStrategyV2.getBuilder(); builder.setQuery(new TermQueryBuilder("edgeSearch",IndexingUtils.createContextName(applicationScope,edge))); return getEntitySizeAggregation(builder); }
/** * Tests writing a document to a new index to ensure it's working correctly. See this post: * http://s.apache.org/index-missing-exception */ private void testNewIndex() { // create the document, this ensures the index is ready // Immediately create a document and remove it to ensure the entire cluster is ready // to receive documents. Occasionally we see errors. // See this post: http://s.apache.org/index-missing-exception if (logger.isTraceEnabled()) { logger.trace("Testing new index name: read {} write {}", alias.getReadAlias(), alias.getWriteAlias()); } final RetryOperation retryOperation = () -> { final String tempId = UUIDGenerator.newTimeUUID().toString(); esProvider.getClient().prepareIndex( alias.getWriteAlias(), VERIFY_TYPE, tempId ) .setSource(DEFAULT_PAYLOAD).get(); if (logger.isTraceEnabled()) { logger.trace("Successfully created new document with docId {} in index read {} write {} and type {}", tempId, alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE); } // delete all types, this way if we miss one it will get cleaned up esProvider.getClient().prepareDelete( alias.getWriteAlias(), VERIFY_TYPE, tempId).get(); if (logger.isTraceEnabled()) { logger.trace("Successfully deleted documents in read {} write {} and type {} with id {}", alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE, tempId); } return true; }; doInRetry(retryOperation); }
.actionGet(); candidates = aggregateScrollResults(candidates, searchResponse, null);
public String[] getIndexes() { Set<String> indexSet = new HashSet<>(); List<String> reads = Arrays.asList(getIndexes(AliasType.Read)); List<String> writes = Arrays.asList(getIndexes(AliasType.Write)); indexSet.addAll(reads); indexSet.addAll(writes); return indexSet.toArray(new String[0]); }
public Observable<IndexRefreshCommandInfo> refreshAsync() { refreshIndexMeter.mark(); final long start = System.currentTimeMillis(); String[] indexes = getIndexes(); if (indexes.length == 0) { if (logger.isTraceEnabled()) { logger.trace("Not refreshing indexes. none found"); } } //Added For Graphite Metrics RefreshResponse response = esProvider.getClient().admin().indices().prepareRefresh(indexes).execute().actionGet(); int failedShards = response.getFailedShards(); int successfulShards = response.getSuccessfulShards(); ShardOperationFailedException[] sfes = response.getShardFailures(); if (sfes != null) { for (ShardOperationFailedException sfe : sfes) { logger.error("Failed to refresh index:{} reason:{}", sfe.index(), sfe.reason()); } } if (logger.isTraceEnabled()) { logger.trace("Refreshed indexes: {},success:{} failed:{} ", StringUtils.join(indexes, ", "), successfulShards, failedShards); } IndexRefreshCommandInfo refreshResults = new IndexRefreshCommandInfo(failedShards == 0, System.currentTimeMillis() - start); return ObservableTimer.time(Observable.just(refreshResults), refreshTimer); }
/** * Check health of this specific index. */ @Override public Health getIndexHealth() { try { String[] indexNames = this.getIndexes(); final ActionFuture<ClusterHealthResponse> future = esProvider.getClient().admin().cluster().health( new ClusterHealthRequest( indexNames ) ); //only wait 2 seconds max ClusterHealthResponse chr = future.actionGet(2000); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
String[] indexNames = getIndexes(AliasType.Write);
/** * Completely delete an index. */ public Observable deleteApplication() { String idString = applicationId(applicationScope.getApplication()); final TermQueryBuilder tqb = QueryBuilders.termQuery(APPLICATION_ID_FIELDNAME, idString); final String[] indexes = getIndexes(); //Added For Graphite Metrics return Observable.from( indexes ).flatMap( index -> { final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute(); response.addListener( new ActionListener<DeleteByQueryResponse>() { @Override public void onResponse( DeleteByQueryResponse response ) { checkDeleteByQueryResponse( tqb, response ); } @Override public void onFailure( Throwable e ) { logger.error( "Failed on delete index", e.getMessage() ); } } ); return Observable.from( response ); } ).doOnError( t -> logger.error( "Failed on delete application", t.getMessage() ) ); }