org.elasticsearch.hadoop.serialization.dto.IndicesAliases Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-spark-20_2.11 Show documentation
Show all versions of elasticsearch-spark-20_2.11 Show documentation
Elasticsearch Spark (for Spark 2.X)
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.hadoop.serialization.dto;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class IndicesAliases {
private final Map > indices;
private IndicesAliases(Map > indices) {
this.indices = indices;
}
public Map getAliases(String index) {
return indices.get(index);
}
public static IndicesAliases parse(Map resp) {
final Map > indices = new HashMap > ();
for (Map.Entry index : resp.entrySet()) {
final Map metadata = (Map) index.getValue();
final Map > aliases = (Map >) metadata.get("aliases");
final Map indexAliases = new HashMap ();
indices.put(index.getKey(), indexAliases);
for (Map.Entry > entry : aliases.entrySet()) {
String name = entry.getKey();
Map aliasMetadata = entry.getValue();
String searchRouting = null;
String indexRouting = null;
Map filter = null;
if (aliasMetadata.containsKey("search_routing")) {
searchRouting = (String) aliasMetadata.get("search_routing");
}
if (aliasMetadata.containsKey("index_routing")) {
indexRouting = (String) aliasMetadata.get("index_routing");
}
if (aliasMetadata.containsKey("filter")) {
filter = (Map) aliasMetadata.get("filter");
}
Alias alias = new Alias(name, searchRouting, indexRouting, filter);
indexAliases.put(alias.name, alias);
}
}
return new IndicesAliases(Collections.unmodifiableMap(indices));
}
public static class Alias {
private final String name;
private final String searchRouting;
private final String indexRouting;
private final Map filter;
Alias(String name, String searchRouting, String indexRouting, Map filter) {
this.name = name;
this.searchRouting = searchRouting;
this.indexRouting = indexRouting;
this.filter = filter;
}
public String getName() {
return name;
}
public String getSearchRouting() {
return searchRouting;
}
public String getIndexRouting() {
return indexRouting;
}
public Map getFilter() {
return filter;
}
@Override
public String toString() {
return "Alias{" +
"name='" + name + '\'' +
", searchRouting='" + searchRouting + '\'' +
", indexRouting='" + indexRouting + '\'' +
", filter=" + filter +
'}';
}
}
}