private void addMappingToIndex(String indexName, String mappingType, String mappingFilename) throws IOException { GetMappingsResponse getMappingsResponse = elasticSearchClient.admin() .indices() .prepareGetMappings(indexName) .addTypes(mappingType) .execute() .actionGet(); if (getMappingsResponse.mappings().isEmpty()) { logger.info("Adding the workflow type mappings"); InputStream stream = ElasticSearchDAOV5.class.getResourceAsStream(mappingFilename); byte[] bytes = IOUtils.toByteArray(stream); String source = new String(bytes); try { elasticSearchClient.admin() .indices() .preparePutMapping(indexName) .setType(mappingType) .setSource(source) .execute() .actionGet(); } catch (Exception e) { logger.error("Failed to init index mappings", e); } } }
public boolean isEmpty() { return entries.isEmpty(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return toXContent(builder, params, indexToDefaultSettings.isEmpty()); }
@Override public String toString() { if (global.isEmpty() && indices().isEmpty()) { return ""; } StringBuilder sb = new StringBuilder(); sb.append("blocks: \n"); if (global.isEmpty() == false) { sb.append(" _global_:\n"); for (ClusterBlock block : global) { sb.append(" ").append(block); } } for (ObjectObjectCursor<String, Set<ClusterBlock>> entry : indices()) { sb.append(" ").append(entry.key).append(":\n"); for (ClusterBlock block : entry.value) { sb.append(" ").append(block); } } sb.append("\n"); return sb.toString(); }
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (!mappers.isEmpty()) { // sort the mappers so we get consistent serialization format Mapper[] sortedMappers = mappers.values().toArray(Mapper.class); Arrays.sort(sortedMappers, new Comparator<Mapper>() { @Override public int compare(Mapper o1, Mapper o2) { return o1.name().compareTo(o2.name()); } }); builder.startObject("fields"); for (Mapper mapper : sortedMappers) { mapper.toXContent(builder, params); } builder.endObject(); } return builder; } }
private XContentBuilder toXContent(XContentBuilder builder, Params params, boolean omitEmptySettings) throws IOException { builder.startObject(); for (ObjectObjectCursor<String, Settings> cursor : getIndexToSettings()) { // no settings, jump over it to shorten the response data if (omitEmptySettings && cursor.value.isEmpty()) { continue; } builder.startObject(cursor.key); builder.startObject("settings"); cursor.value.toXContent(builder, params); builder.endObject(); if (indexToDefaultSettings.isEmpty() == false) { builder.startObject("defaults"); indexToDefaultSettings.get(cursor.key).toXContent(builder, params); builder.endObject(); } builder.endObject(); } builder.endObject(); return builder; }
if (metaData.customs().isEmpty() == false) { sb.append("metadata customs:\n"); for (final ObjectObjectCursor<String, MetaData.Custom> cursor : metaData.customs()) { sb.append(routingTable()); sb.append(getRoutingNodes()); if (customs.isEmpty() == false) { sb.append("customs:\n"); for (ObjectObjectCursor<String, Custom> cursor : customs) {
if (context == XContentContext.API && !metaData.indices().isEmpty()) { builder.startObject("indices"); for (IndexMetaData indexMetaData : metaData) {
private Decision earlyTerminate(RoutingAllocation allocation, ImmutableOpenMap<String, DiskUsage> usages) { // Always allow allocation if the decider is disabled if (diskThresholdSettings.isEnabled() == false) { return allocation.decision(Decision.YES, NAME, "the disk threshold decider is disabled"); } // Allow allocation regardless if only a single data node is available if (allocation.nodes().getDataNodes().size() <= 1) { if (logger.isTraceEnabled()) { logger.trace("only a single data node is present, allowing allocation"); } return allocation.decision(Decision.YES, NAME, "there is only a single data node present"); } // Fail open there is no info available final ClusterInfo clusterInfo = allocation.clusterInfo(); if (clusterInfo == null) { if (logger.isTraceEnabled()) { logger.trace("cluster info unavailable for disk threshold decider, allowing allocation."); } return allocation.decision(Decision.YES, NAME, "the cluster info is unavailable"); } // Fail open if there are no disk usages available if (usages.isEmpty()) { if (logger.isTraceEnabled()) { logger.trace("unable to determine disk usages for disk-aware allocation, allowing allocation"); } return allocation.decision(Decision.YES, NAME, "disk usages are unavailable"); } return null; }
public void parse(FieldMapper mainField, ParseContext context) throws IOException { // TODO: multi fields are really just copy fields, we just need to expose "sub fields" or something that can be part // of the mappings if (mappers.isEmpty()) { return; } context = context.createMultiFieldContext(); context.path().add(mainField.simpleName()); for (ObjectCursor<FieldMapper> cursor : mappers.values()) { cursor.value.parse(context); } context.path().remove(); }
if (!blocks().indices().isEmpty()) { builder.startObject("indices"); for (ObjectObjectCursor<String, Set<ClusterBlock>> entry : blocks().indices()) {
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return toXContent(builder, params, indexToDefaultSettings.isEmpty()); }
private boolean waitingShardsStartedOrUnassigned(ClusterChangedEvent event) { SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE); if (curr != null) { for (SnapshotsInProgress.Entry entry : curr.entries()) { if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) { for (ObjectCursor<String> index : entry.waitingIndices().keys()) { if (event.indexRoutingTableChanged(index.value)) { IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index.value); for (ShardId shardId : entry.waitingIndices().get(index.value)) { ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard(); if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) { return true; } } } } } } } return false; }
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData).state(IndexMetaData.State.OPEN).index(renamedIndexName); indexMdBuilder.settings(Settings.builder().put(snapshotIndexMetaData.getSettings()).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())); if (!request.includeAliases() && !snapshotIndexMetaData.getAliases().isEmpty()) { if (!request.includeAliases()) { if (!snapshotIndexMetaData.getAliases().isEmpty()) { indexMdBuilder.removeAllAliases();
if (mappings.isEmpty()) { listener.onResponse(new TypesExistsResponse(false)); return;
/** * Check if a type already exists * @param client Elasticsearch client * @param index Index name * @param type Type name * @return true if type already exists * @throws Exception if the elasticsearch call is failing */ @Deprecated public static boolean isTypeExist(Client client, String index, String type) throws Exception { return !client.admin().indices().prepareGetMappings(index).setTypes(type).get().getMappings().isEmpty(); }
@Override public boolean mappingExists(String indexName, String type) { GetMappingsResponse mappings = client.admin().indices().prepareGetMappings(indexName).execute().actionGet(); if (mappings == null || mappings.getMappings().isEmpty()) { return false; } // The real index might have another name if indexName is an alias so we check the mapping of the first item. return mappings.getMappings().values().iterator().next().value.containsKey(type); }
@Override public ClusterState execute(ClusterState currentState) { assert currentState.metaData().indices().isEmpty();
public void parse(FieldMapper mainField, ParseContext context) throws IOException { // TODO: multi fields are really just copy fields, we just need to expose "sub fields" or something that can be part of the mappings if (mappers.isEmpty()) { return; } context = context.createMultiFieldContext(); context.path().add(mainField.simpleName()); for (ObjectCursor<FieldMapper> cursor : mappers.values()) { cursor.value.parse(context); } context.path().remove(); }
public void create(FieldMapper mainField, ParseContext context, Object val) throws IOException { // TODO: multi fields are really just copy fields, we just need to expose "sub fields" or something that can be part of the mappings if (mappers.isEmpty()) { return; } context = context.createMultiFieldContext(); context.path().add(mainField.simpleName()); for (ObjectCursor<FieldMapper> cursor : mappers.values()) { cursor.value.createField(context, val); } context.path().remove(); }