Example usage for org.apache.solr.client.solrj.response.schema SchemaResponse.UpdateResponse getResponse

List of usage examples for org.apache.solr.client.solrj.response.schema SchemaResponse.UpdateResponse getResponse

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response.schema SchemaResponse.UpdateResponse getResponse.

Prototype

@Override
    public NamedList<Object> getResponse() 

Source Link

Usage

From source file:com.hurence.logisland.service.solr.api.SolrClientService.java

License:Apache License

public boolean removeMapping(String collectionName, List<Map<String, Object>> mapping)
        throws DatastoreClientServiceException {
    Boolean result = true;/* w  w w  . j  a v  a 2 s .  co m*/
    try {
        for (Map<String, Object> field : mapping) {
            SchemaRequest.DeleteField schemaRequest = new SchemaRequest.DeleteField((String) field.get("name"));
            SchemaResponse.UpdateResponse response = schemaRequest.process(getClient(), collectionName);
            result = result && response.getStatus() == 0 && response.getResponse().get("errors") == null;
        }

        getClient().commit(collectionName);
        refreshCollection(collectionName);

        return result;
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    return false;
}

From source file:com.hurence.logisland.service.solr.api.SolrClientService.java

License:Apache License

public boolean putMapping(String collectionName, List<Map<String, Object>> mapping)
        throws DatastoreClientServiceException {
    Boolean result = true;//www. jav  a  2 s .  c  o m
    try {
        for (Map<String, Object> field : mapping) {
            SchemaRequest.AddField schemaRequest = new SchemaRequest.AddField(field);

            if (isCloud()) {
                Set<String> params = new HashSet<>();
                params.add("updateTimeoutSecs=" + getSchemaUpdateTimeout());
                schemaRequest.setQueryParams(params);
            }

            SchemaResponse.UpdateResponse response = schemaRequest.process(getClient(), collectionName);
            result = result && response.getStatus() == 0 && response.getResponse().get("errors") == null;
        }

        getClient().commit(collectionName);
        refreshCollection(collectionName);

        return result;
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    return false;
}

From source file:org.wso2.extension.siddhi.store.solr.impl.SolrClientServiceImpl.java

License:Open Source License

public boolean updateSolrSchema(String table, SolrSchema solrSchema, boolean merge)
        throws SolrClientServiceException {
    SolrSchema oldSchema;/*from ww  w  . j ava 2 s  .co m*/
    List<SchemaRequest.Update> updateFields = new ArrayList<>();
    SolrClient client = getSolrServiceClientByCollection(table);
    SchemaResponse.UpdateResponse updateResponse;
    try {
        oldSchema = getSolrSchema(table);
    } catch (SolrSchemaNotFoundException e) {
        throw new SolrClientServiceException("Error while retrieving  the Solr schema for table: " + table
                + ", " + "error: " + e.getMessage(), e);
    }

    updateFields = createUpdateFields(solrSchema, merge, oldSchema, updateFields);
    SchemaRequest.MultiUpdate multiUpdateRequest = new SchemaRequest.MultiUpdate(updateFields);
    try {
        updateResponse = multiUpdateRequest.process(client, table);
        // UpdateResponse does not have a "getErrorMessages()" method, so we check
        // if the errors attribute exists in the response
        Object errors = updateResponse.getResponse().get(ATTR_ERRORS);
        if (updateResponse.getStatus() == 0 && errors == null) {
            return true;
        } else {
            throw new SolrClientServiceException("Couldn't update index schema, Response code: "
                    + updateResponse.getStatus() + ", errors: " + errors);
        }
    } catch (SolrServerException | IOException | SolrException e) {
        throw new SolrClientServiceException(
                "error while updating the index schema for table: " + table + " error: " + e.getMessage(), e);
    }
}