Example usage for org.apache.solr.client.solrj.response.schema SchemaRepresentation getFields

List of usage examples for org.apache.solr.client.solrj.response.schema SchemaRepresentation getFields

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response.schema SchemaRepresentation getFields.

Prototype

public List<Map<String, Object>> getFields() 

Source Link

Usage

From source file:com.streamsets.pipeline.solr.impl.SolrTarget06.java

License:Apache License

private void getRequiredFieldNames() throws SolrServerException, IOException {
    SchemaRequest schemaRequest = new SchemaRequest();
    SchemaResponse schemaResponse = schemaRequest.process(solrClient);
    SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
    List<Map<String, Object>> fields = schemaRepresentation.getFields();
    for (Map<String, Object> field : fields) {
        if (field.containsKey(REQUIRED) && field.get(REQUIRED) == "true") {
            requiredFieldNamesMap.add(field.get(REQUIRED).toString());
        }/*w w w. ja v a  2  s  . com*/
    }
}

From source file:org.apache.metron.solr.dao.SolrColumnMetadataDao.java

License:Apache License

protected List<Map<String, Object>> getIndexFields(String index) throws IOException, SolrServerException {
    List<Map<String, Object>> indexFields = new ArrayList<>();

    // Get all the fields in use, including dynamic fields
    LukeRequest lukeRequest = new LukeRequest();
    LukeResponse lukeResponse = lukeRequest.process(client, index);
    for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) {
        Map<String, Object> fieldData = new HashMap<>();
        fieldData.put("name", field.getValue().getName());
        fieldData.put("type", field.getValue().getType());
        indexFields.add(fieldData);/*from  w w w  . jav  a 2s.  c  o m*/

    }

    // Get all the schema fields
    SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index)
            .getSchemaRepresentation();
    indexFields.addAll(schemaRepresentation.getFields());

    return indexFields;
}

From source file:org.apache.storm.solr.schema.builder.RestJsonSchemaBuilderV2.java

License:Apache License

@Override
public void buildSchema() throws IOException {
    SolrClient solrClient = null;//from  w  w w  .  j  a  v  a2s .  c om
    try {
        solrClient = new CloudSolrClient(solrConfig.getZkHostString());
        SchemaRequest schemaRequest = new SchemaRequest();
        logger.debug("Downloading schema for collection: {}", collection);
        SchemaResponse schemaResponse = schemaRequest.process(solrClient, collection);
        logger.debug("SchemaResponse Schema: {}", schemaResponse);
        SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();

        schema.setName(schemaRepresentation.getName());
        schema.setVersion(Float.toString(schemaRepresentation.getVersion()));
        schema.setUniqueKey(schemaRepresentation.getUniqueKey());
        schema.setFieldTypes(getFieldTypes(schemaRepresentation));
        schema.setFields(getFields(schemaRepresentation.getFields()));
        schema.setDynamicFields(getFields(schemaRepresentation.getDynamicFields()));
        schema.setCopyFields(getCopyFields(schemaRepresentation));
    } catch (SolrServerException e) {
        logger.error("Error while getting schema for collection: {}", collection, e);
        throw new IOException("Error while getting schema for collection :" + collection, e);
    } finally {
        if (solrClient != null) {
            solrClient.close();
        }
    }
}

From source file:org.springframework.data.solr.core.schema.DefaultSchemaOperations.java

License:Apache License

@Override
public SchemaDefinition readSchema() {

    SchemaRepresentation representation = template.execute(
            solrClient -> new SchemaRequest().process(solrClient, collection).getSchemaRepresentation());

    SchemaDefinition sd = new SchemaDefinition(collection);

    for (Map<String, Object> fieldValueMap : representation.getFields()) {
        sd.addFieldDefinition(FieldDefinition.fromMap(fieldValueMap));
    }//from   w  w w.  j  a v  a  2s .c  o  m
    for (Map<String, Object> fieldValueMap : representation.getCopyFields()) {

        CopyFieldDefinition cf = CopyFieldDefinition.fromMap(fieldValueMap);
        sd.addCopyField(cf);

        if (sd.getFieldDefinition(cf.getSource()) != null) {
            sd.getFieldDefinition(cf.getSource()).setCopyFields(cf.getDestination());
        }
    }

    return sd;
}