public Map<String, GeoField> sampleGeoFields(Mapping mapping) { Map<String, GeoType> fields = MappingUtils.geoFields(mapping); Map<String, Object> geoMapping = client.sampleForFields(resources.getResourceRead(), fields.keySet()); Map<String, GeoField> geoInfo = new LinkedHashMap<String, GeoField>(); for (Entry<String, GeoType> geoEntry : fields.entrySet()) { String fieldName = geoEntry.getKey(); geoInfo.put(fieldName, MappingUtils.parseGeoInfo(geoEntry.getValue(), geoMapping.get(fieldName))); } return geoInfo; }
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); if (resources.getResourceWrite().isTyped()) { client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type() + "/_query?q=*"); } else { client.delete(resources.getResourceWrite().index() + "/_query?q=*"); StringBuilder sb = new StringBuilder(resources.getResourceWrite().index()); if (resources.getResourceWrite().isTyped()) { sb.append('/').append(resources.getResourceWrite().type()); flush(); client.refresh(resources.getResourceWrite());
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type() + "/_query?q=*"); } catch (EsHadoopInvalidRequest ehir) { log.info("Skipping delete by query as the plugin is not installed..."); StringBuilder sb = new StringBuilder(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); sb.append("/_search?scroll=10m&_source=false&size="); sb.append(batchSize); flush(); client.refresh(resources.getResourceWrite());
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type() + "/_query?q=*"); } catch (EsHadoopInvalidRequest ehir) { log.info("Skipping delete by query as the plugin is not installed..."); StringBuilder sb = new StringBuilder(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); sb.append("/_search?scroll=10m&_source=false&size="); sb.append(batchSize); flush(); client.refresh(resources.getResourceWrite());
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type() + "/_query?q=*"); } catch (EsHadoopInvalidRequest ehir) { log.info("Skipping delete by query as the plugin is not installed..."); StringBuilder sb = new StringBuilder(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); sb.append("/_search?scroll=10m&_source=false&size="); sb.append(batchSize); flush(); client.refresh(resources.getResourceWrite());
protected Map<ShardInfo, NodeInfo> doGetWriteTargetPrimaryShards(boolean clientNodesOnly) { List<List<Map<String, Object>>> info = client.targetShards(resources.getResourceWrite().index(), SettingsUtils.getFixedRouting(settings)); Map<ShardInfo, NodeInfo> shards = new LinkedHashMap<ShardInfo, NodeInfo>(); List<NodeInfo> nodes = client.getHttpNodes(clientNodesOnly); Map<String, NodeInfo> nodeMap = new HashMap<String, NodeInfo>(nodes.size()); for (NodeInfo node : nodes) { nodeMap.put(node.getId(), node); } for (List<Map<String, Object>> shardGroup : info) { // consider only primary shards for (Map<String, Object> shardData : shardGroup) { ShardInfo shard = new ShardInfo(shardData); if (shard.isPrimary()) { NodeInfo node = nodeMap.get(shard.getNode()); if (node == null) { log.warn(String.format("Cannot find node with id [%s] (is HTTP enabled?) from shard [%s] in nodes [%s]; layout [%s]", shard.getNode(), shard, nodes, info)); return null; } shards.put(shard, node); break; } } } return shards; }
protected Map<ShardInfo, NodeInfo> doGetWriteTargetPrimaryShards(boolean clientNodesOnly) { List<List<Map<String, Object>>> info = client.targetShards(resources.getResourceWrite().index(), SettingsUtils.getFixedRouting(settings)); Map<ShardInfo, NodeInfo> shards = new LinkedHashMap<ShardInfo, NodeInfo>(); List<NodeInfo> nodes = client.getHttpNodes(clientNodesOnly); Map<String, NodeInfo> nodeMap = new HashMap<String, NodeInfo>(nodes.size()); for (NodeInfo node : nodes) { nodeMap.put(node.getId(), node); } for (List<Map<String, Object>> shardGroup : info) { // consider only primary shards for (Map<String, Object> shardData : shardGroup) { ShardInfo shard = new ShardInfo(shardData); if (shard.isPrimary()) { NodeInfo node = nodeMap.get(shard.getNode()); if (node == null) { log.warn(String.format("Cannot find node with id [%s] (is HTTP enabled?) from shard [%s] in nodes [%s]; layout [%s]", shard.getNode(), shard, nodes, info)); return null; } shards.put(shard, node); break; } } } return shards; }
protected Map<ShardInfo, NodeInfo> doGetWriteTargetPrimaryShards(boolean clientNodesOnly) { List<List<Map<String, Object>>> info = client.targetShards(resources.getResourceWrite().index(), SettingsUtils.getFixedRouting(settings)); Map<ShardInfo, NodeInfo> shards = new LinkedHashMap<ShardInfo, NodeInfo>(); List<NodeInfo> nodes = client.getHttpNodes(clientNodesOnly); Map<String, NodeInfo> nodeMap = new HashMap<String, NodeInfo>(nodes.size()); for (NodeInfo node : nodes) { nodeMap.put(node.getId(), node); } for (List<Map<String, Object>> shardGroup : info) { // consider only primary shards for (Map<String, Object> shardData : shardGroup) { ShardInfo shard = new ShardInfo(shardData); if (shard.isPrimary()) { NodeInfo node = nodeMap.get(shard.getNode()); if (node == null) { log.warn(String.format("Cannot find node with id [%s] (is HTTP enabled?) from shard [%s] in nodes [%s]; layout [%s]", shard.getNode(), shard, nodes, info)); return null; } shards.put(shard, node); break; } } } return shards; }
public boolean indexExists(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); // cheap hit boolean exists = client.indexExists(res.index()); if (exists && StringUtils.hasText(res.type())) { exists = client.typeExists(res.index(), res.type()); } // could be a _all or a pattern which is valid for read // try again by asking the mapping - could be expensive if (!exists && read) { try { // make sure the mapping is null since the index might exist but the type might be missing exists = !client.getMapping(res.mapping()).isEmpty(); } catch (EsHadoopInvalidRequest ex) { exists = false; } } return exists; }
public boolean indexExists(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); // cheap hit boolean exists = client.indexExists(res.index()); if (exists && StringUtils.hasText(res.type())) { exists = client.typeExists(res.index(), res.type()); } // could be a _all or a pattern which is valid for read // try again by asking the mapping - could be expensive if (!exists && read) { try { // make sure the mapping is null since the index might exist but the type might be missing exists = !client.getMapping(res.mapping()).isEmpty(); } catch (EsHadoopInvalidRequest ex) { exists = false; } } return exists; }
public boolean indexExists(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); // cheap hit boolean exists = client.indexExists(res.index()); if (exists && StringUtils.hasText(res.type())) { exists = client.typeExists(res.index(), res.type()); } // could be a _all or a pattern which is valid for read // try again by asking the mapping - could be expensive if (!exists && read) { try { // make sure the mapping is null since the index might exist but the type might be missing exists = !client.getMapping(res.mapping()).isEmpty(); } catch (EsHadoopInvalidRequest ex) { exists = false; } } return exists; }
public MappingSet getMappings() { return FieldParser.parseMapping(client.getMapping(resources.getResourceRead().mapping())); }
protected List<List<Map<String, Object>>> doGetReadTargetShards() { return client.targetShards(resources.getResourceRead().index(), SettingsUtils.getFixedRouting(settings)); }
public void putMapping(BytesArray mapping) { client.putMapping(resources.getResourceWrite().index(), resources.getResourceWrite().mapping(), mapping.bytes()); }
protected List<List<Map<String, Object>>> doGetReadTargetShards() { return client.targetShards(resources.getResourceRead().index(), SettingsUtils.getFixedRouting(settings)); }
public MappingSet getMappings() { return FieldParser.parseMapping(client.getMapping(resources.getResourceRead().mapping())); }
public MappingSet getMappings() { return FieldParser.parseMapping(client.getMapping(resources.getResourceRead().mapping())); }
public boolean waitForYellow() { return client.waitForHealth(resources.getResourceWrite().index(), RestClient.Health.YELLOW, TimeValue.timeValueSeconds(10)); }
public boolean touch() { return client.touch(resources.getResourceWrite().index()); }
private boolean isReadIndexConcrete() { String index = resources.getResourceRead().index(); return !(index.contains(",") || index.contains("*") || client.isAlias(resources.getResourceRead().aliases())); }