/** * This method is used to get the field names that are indexed from the solr managed schema * @param solrClient a solrclient instance * @return a list of field names */ private List<String> getFieldNamesFromSolrSchema(SolrClient solrClient) { List<String> fieldNames = null; try { SchemaRequest.Fields request = new SchemaRequest.Fields(); SchemaResponse.FieldsResponse response = request.process(solrClient); List<Map<String, Object>> fieldList = response.getFields(); fieldNames = new ArrayList<String>(); for (int i = 0; i < fieldList.size(); i++) { String value = fieldList.get(i).get("name").toString(); if (("_root_").equals(value) || ("_text_").equals(value) || ("_version_").equals(value) || ("facet_").equals(value)) { continue; } fieldNames.add(value); } } catch (Exception e) { LOG.error("Retrieving fieldNames failed", e); e.printStackTrace(); } return fieldNames; }
/** * This method is used to get the field names that are indexed from the solr managed schema * @param solrClient a solrclient instance * @return a list of field names */ private List<String> getFieldNamesFromSolrSchema(SolrClient solrClient) { List<String> fieldNames = null; try { SchemaRequest.Fields request = new SchemaRequest.Fields(); SchemaResponse.FieldsResponse response = request.process(solrClient); List<Map<String, Object>> fieldList = response.getFields(); fieldNames = new ArrayList<String>(); for (int i = 0; i < fieldList.size(); i++) { String value = fieldList.get(i).get("name").toString(); if (("_root_").equals(value) || ("_text_").equals(value) || ("_version_").equals(value) || ("facet_").equals(value)) { continue; } fieldNames.add(value); } } catch (Exception e) { LOG.error("Retrieving fieldNames failed", e); e.printStackTrace(); } return fieldNames; }
private static Map<String, Field> getFields(SolrClient client, String collectionName) throws GenericException { SchemaRequest.Fields fields = new SchemaRequest.Fields(); FieldsResponse response; try { response = fields.process(client, collectionName); return response.getFields().stream().map(f -> new Field(f)) .collect(Collectors.toMap(Field::getName, Function.identity())); } catch (SolrServerException | IOException e) { throw new GenericException("Could not get schema fields", e); } }
/** * Returns all Solr fields that have <code>stored</code> set to <code>true</code>. * * @param solrCore Solr core name * @return a list of stored fields on success, and an empty list otherwise. */ public List<String> getStoredFields(String solrCore) { List<String> storedFields = new ArrayList<String>(); SolrClient solrClient = getQueryingSolrClient(); final SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields(); try { SchemaResponse.FieldsResponse fieldsResponse = fieldsSchemaRequest.process(solrClient, solrCore); List<Map<String, Object>> fields = fieldsResponse.getFields(); for (Map map : fields) { if (map.containsKey("stored")) { Boolean stored = (Boolean) map.get("stored"); if (stored) { String fieldName = (String) map.get("name"); storedFields.add(fieldName); } } } } catch (SolrServerException e) { LOG.error("Error fetching stored fields of schema '{}'. ", solrCore, e); } catch (IOException e) { LOG.error("Error fetching stored fields of schema '{}'. ", solrCore, e); } return storedFields; }
/** * Returns all Solr fields that have <code>indexed</code> set to <code>true</code> * * @param solrCore Solr core name * @return a list of indexed fields on success, and an empty list otherwise. */ public List<String> getIndexedFields(String solrCore) { List<String> availableIndexedFields = new ArrayList<String>(); final SolrClient solrClient = getQueryingSolrClient(); final SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields(); try { SchemaResponse.FieldsResponse fieldsResponse = fieldsSchemaRequest.process(solrClient, solrCore); List<Map<String, Object>> fields = fieldsResponse.getFields(); for (Map map : fields) { if (map.containsKey("indexed")) { Boolean stored = (Boolean) map.get("indexed"); if (stored) { String fieldName = (String) map.get("name"); availableIndexedFields.add(fieldName); } } } } catch (SolrServerException e) { LOG.error("Error fetching indexed fields of schema '{}'.", solrCore, e); } catch (IOException e) { LOG.error("Error fetching indexed fields of schema '{}'. ", solrCore, e); } return availableIndexedFields; }
public List<Map<String, Object>> getMapping(String collectionName) throws IOException, SolrServerException { SchemaRequest.Fields request = new SchemaRequest.Fields(); SchemaResponse.FieldsResponse response = request.process(getClient(), collectionName); return response.getFields(); }