public SearchRequestBuilder resource(Resource resource) { this.indices = resource.index(); if (resource.isTyped()) { this.types = resource.type(); } else { this.types = null; } return this; }
endpoint = resource.index() + "/" + resource.type();
@Override public BulkOutputGenerator addSuccess(String operation, int status) { Assert.notNull(resource); items.add(getSuccess() .replace(OP, operation) .replace(IDX, resource.index()) .replace(TYPE, resource.type()) .replace(ID, UUID.randomUUID().toString()) .replace(VER, "1") .replace(STAT, "201") ); return this; }
@Override public BulkOutputGenerator addFailure(String operation, int status, String type, String errorMessage) { Assert.notNull(resource); errors = true; items.add(getFailure() .replace(OP, operation) .replace(IDX, resource.index()) .replace(TYPE, resource.type()) .replace(ID, UUID.randomUUID().toString()) .replace(STAT, Integer.toString(status)) .replace(ETYPE, type) .replace(EMESG, errorMessage) ); return this; }
public MappingSet getMappings(Resource indexResource) { if (indexResource.isTyped()) { return getMappings(indexResource.index() + "/_mapping/" + indexResource.type(), true); } else { return getMappings(indexResource.index() + "/_mapping", false); } }
@Override public BulkOutputGenerator addRejection(String operation) { Assert.notNull(resource); errors = true; items.add(getFailure() .replace(OP, operation) .replace(IDX, resource.index()) .replace(TYPE, resource.type()) .replace(ID, UUID.randomUUID().toString()) .replace(STAT, Integer.toString(getRejectedStatus())) .replace(ETYPE, getRejectionType()) .replace(EMESG, getRejectionMsg()) ); return this; }
public String postDocument(Resource resource, BytesArray document) throws IOException { // If untyped, the type() method returns '_doc' Request request = new SimpleRequest(Method.POST, null, resource.index() + "/" + resource.type(), null, document); Response response = execute(request, true); Object id = parseContent(response.body(), "_id"); if (id == null || !StringUtils.hasText(id.toString())) { throw new EsHadoopInvalidRequest( String.format("Could not determine successful write operation. Request[%s > %s] Response[%s]", request.method(), request.path(), IOUtils.asString(response.body()) ) ); } return id.toString(); }
numDocs = client.count(index, readResource.type(), Integer.toString(shardId), query); } else { numDocs = client.countIndexShard(index, Integer.toString(shardId), query);
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)); } }
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); 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());
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; }
public Map<String, GeoField> sampleGeoFields(Mapping mapping) { Map<String, GeoType> fields = MappingUtils.geoFields(mapping); Map<String, Object> geoMapping = client.sampleForFields(resources.getResourceRead().index(), resources.getResourceRead().type(), 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; }
public Map<String, GeoField> sampleGeoFields(Mapping mapping) { Map<String, GeoType> fields = MappingUtils.geoFields(mapping); Map<String, Object> geoMapping = client.sampleForFields(resources.getResourceRead().index(), resources.getResourceRead().type(), 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; }
public Map<String, GeoField> sampleGeoFields(Mapping mapping) { Map<String, GeoType> fields = MappingUtils.geoFields(mapping); Map<String, Object> geoMapping = client.sampleForFields(resources.getResourceRead().index(), resources.getResourceRead().type(), 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; }
public long count(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); return client.count(res.index() + "/" + res.type(), QueryUtils.parseQuery(settings)); }
public String postDocument(Resource resource, BytesArray document) throws IOException { Request request = new SimpleRequest(Method.POST, null, resource.index() + "/" + resource.type(), null, document); Response response = execute(request, true); Object id = parseContent(response.body(), "_id"); if (id == null || !StringUtils.hasText(id.toString())) { throw new EsHadoopInvalidRequest( String.format("Could not determine successful write operation. Request[%s > %s] Response[%s]", request.method(), request.path(), IOUtils.asString(response.body()) ) ); } return id.toString(); }
public long count(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); return client.count(res.index() + "/" + res.type(), QueryUtils.parseQuery(settings)); }
public long count(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); return client.count(res.index() + "/" + res.type(), QueryUtils.parseQuery(settings)); }
public String postDocument(Resource resource, BytesArray document) throws IOException { Request request = new SimpleRequest(Method.POST, null, resource.index() + "/" + resource.type(), null, document); Response response = execute(request, true); Object id = parseContent(response.body(), "_id"); if (id == null || !StringUtils.hasText(id.toString())) { throw new EsHadoopInvalidRequest( String.format("Could not determine successful write operation. Request[%s > %s] Response[%s]", request.method(), request.path(), IOUtils.asString(response.body()) ) ); } return id.toString(); }
public String postDocument(Resource resource, BytesArray document) throws IOException { Request request = new SimpleRequest(Method.POST, null, resource.index() + "/" + resource.type(), null, document); Response response = execute(request, true); Object id = parseContent(response.body(), "_id"); if (id == null || !StringUtils.hasText(id.toString())) { throw new EsHadoopInvalidRequest( String.format("Could not determine successful write operation. Request[%s > %s] Response[%s]", request.method(), request.path(), IOUtils.asString(response.body()) ) ); } return id.toString(); }