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); } // Get all the schema fields SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index) .getSchemaRepresentation(); indexFields.addAll(schemaRepresentation.getFields()); return indexFields; }
/** * Returns all Solr fields that have <code>indexed</code> set to <code>true</code>. This implementation uses * the <code>LukeRequestHandler</code>, as such this method will return dynamic fields as well. * * @param solrCore Solr core name * @return a list of indexed fields on success, and an empty list otherwise. */ public List<String> getIndexedFieldsFromLuke(String solrCore) { List<String> availableIndexedFields = new ArrayList<String>(); SolrClient solrClient = getQueryingSolrClient(); final LukeRequest request = new LukeRequest(); request.setShowSchema(true); LOG.info("Looking up available indexed fields using Luke"); try { LukeResponse response = request.process(solrClient, solrCore); Map<String, LukeResponse.FieldInfo> fields = response.getFieldInfo(); for (LukeResponse.FieldInfo field : fields.values()) { Set<FieldFlag> indexFlags = field.getFlags(); if (indexFlags != null && indexFlags.contains(FieldFlag.INDEXED)) { availableIndexedFields.add(field.getName()); } } } 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); } LOG.info("Found indexed fields [{}]", availableIndexedFields); return availableIndexedFields; }
/** * Determine the names of all multi-valued fields from the data in the index. * * @param solr the solr server to query. * @return A list containing all multi-valued fields, or an empty list if none are found / there aren't any. */ private static List<String> getMultiValuedFields(HttpSolrServer solr) { List<String> result = new ArrayList<>(); try { LukeRequest request = new LukeRequest(); // this needs to be a non-schema request, otherwise we'll miss dynamic fields LukeResponse response = request.process(solr); Map<String, LukeResponse.FieldInfo> fields = response.getFieldInfo(); for (LukeResponse.FieldInfo info : fields.values()) { if (info.getSchema().contains(FieldFlag.MULTI_VALUED.getAbbreviation() + "")) { result.add(info.getName()); } } } catch (IOException | SolrServerException e) { log.fatal("Cannot determine which fields are multi valued: " + e.getMessage(), e); } return result; }
for (String k : keys) { FieldInfo fieldInfo = fis.get(k); String name = fieldInfo.getName(); String type = fieldInfo.getType();