public SearchRequestBuilder resource(Resource resource) { this.indices = resource.index(); if (resource.isTyped()) { this.types = resource.type(); } else { this.types = null; } return this; }
if (resource.isTyped()) { endpoint = resource.index() + "/" + resource.type();
public MappingSet getMappings(Resource indexResource) { if (indexResource.isTyped()) { return getMappings(indexResource.index() + "/_mapping/" + indexResource.type(), true); } else { return getMappings(indexResource.index() + "/_mapping", false); } }
if (readResource.isTyped()) { numDocs = client.count(index, readResource.type(), Integer.toString(shardId), query); } else {
public long count(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); if (res.isTyped()) { return client.count(res.index(), res.type(), QueryUtils.parseQuery(settings)); } else { return client.count(res.index(), QueryUtils.parseQuery(settings)); } }
public boolean resourceExists(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); // cheap hit - works for exact index names, index patterns, the `_all` resource, and alias names boolean exists = client.indexExists(res.index()); // Do we really care if it's typed? // Yes! If the index exists and a type is given, the type should exist on the index as well. if (exists && res.isTyped()) { 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 MappingSet mappings = client.getMappings(res); exists = mappings != null && !mappings.isEmpty(); } catch (EsHadoopInvalidRequest ex) { exists = false; } } return exists; }