private void addFieldNameToSchema(String fieldName, String fieldType, boolean stored, boolean indexed) { if (!fieldNames.contains(fieldName)) { fieldNames.add(fieldName); Map<String, Object> fieldAttributes = new HashMap(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", fieldType); fieldAttributes.put("stored", stored); fieldAttributes.put("indexed", indexed); fieldAttributes.put("multiValued", true); fieldAttributes.put("required", false); try { SchemaRequest.AddField schemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse response = schemaRequest.process(solrClient); } catch (Exception e) { LOG.error("Error while adding fields to the solrclient.", e); e.printStackTrace(); } } }
/** * Adds (or replaces) a field in the schema, set up to copy the values from the field with the locale suffix * trimmed. * * @param name the name of the field to set up * @param multiValued whether the field accepts multiple values or not * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addField(String name, boolean multiValued) throws SolrServerException, IOException { Map<String, Object> fieldDefinition = new LinkedHashMap<>(); fieldDefinition.put("name", name); fieldDefinition.put("type", "text_general_" + getTargetLocale().toString()); fieldDefinition.put("indexed", true); fieldDefinition.put("stored", true); fieldDefinition.put("multiValued", multiValued); // Add or redefine the field UpdateResponse response = new SchemaRequest.AddField(fieldDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceField(fieldDefinition).process(getClient()); } }
/** * Adds (or replaces) a field in the schema, set up to copy the values from the field with the locale suffix * trimmed. * * @param name the name of the field to set up * @param multiValued whether the field accepts multiple values or not * @throws SolrServerException if communicating with the Solr server failed * @throws IOException if communicating with the Solr server failed */ protected void addField(String name, boolean multiValued) throws SolrServerException, IOException { Map<String, Object> fieldDefinition = new LinkedHashMap<>(); fieldDefinition.put("name", name); fieldDefinition.put("type", "text_general_" + getTargetLocale().toString()); fieldDefinition.put("indexed", true); fieldDefinition.put("stored", true); fieldDefinition.put("multiValued", multiValued); // Add or redefine the field UpdateResponse response = new SchemaRequest.AddField(fieldDefinition).process(getClient()); if (response.getResponse().get("errors") != null) { response = new SchemaRequest.ReplaceField(fieldDefinition).process(getClient()); } }
public boolean putMapping(String collectionName, List<Map<String, Object>> mapping) throws DatastoreClientServiceException { Boolean result = true; 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; }
private void addFieldNameToSchema(String fieldName, String fieldType, boolean stored, boolean indexed) { if (!fieldNames.contains(fieldName)) { fieldNames.add(fieldName); Map<String, Object> fieldAttributes = new HashMap(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", fieldType); fieldAttributes.put("stored", stored); fieldAttributes.put("indexed", indexed); fieldAttributes.put("multiValued", true); fieldAttributes.put("required", false); try { SchemaRequest.AddField schemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse response = schemaRequest.process(solrClient); } catch (Exception e) { LOG.error("Error while adding fields to the solrclient.", e); e.printStackTrace(); } } }
private void addFieldNameToSchema(String fieldName, String fieldType, boolean stored, boolean indexed, SolrClient solrClient) throws IOException { Map<String, Object> fieldAttributes = new HashMap(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", fieldType); fieldAttributes.put("stored", stored); fieldAttributes.put("indexed", indexed); fieldAttributes.put("multiValued", true); fieldAttributes.put("required", false); try { SchemaRequest.AddField schemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse response = schemaRequest.process(solrClient); } catch (SolrServerException e) { LOG.error("Error while adding fields to the solrclient.", e); e.printStackTrace(); } }
private void addFieldNameToSchema(String fieldName, String fieldType, boolean stored, boolean indexed, SolrClient solrClient) throws IOException { Map<String, Object> fieldAttributes = new HashMap(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", fieldType); fieldAttributes.put("stored", stored); fieldAttributes.put("indexed", indexed); fieldAttributes.put("multiValued", true); fieldAttributes.put("required", false); try { SchemaRequest.AddField schemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse response = schemaRequest.process(solrClient); } catch (SolrServerException e) { LOG.error("Error while adding fields to the solrclient.", e); e.printStackTrace(); } }
private void addField(final FieldDefinition field) { template.execute(solrClient -> { UpdateResponse response = new SchemaRequest.AddField(field.asMap()).process(solrClient, collection); if (hasErrors(response)) { throw new SchemaModificationException( String.format("Adding field %s with args %s to collection %s failed with status %s. Server returned %s.", field.getName(), field.asMap(), collection, response.getStatus(), response)); } return Integer.valueOf(response.getStatus()); }); if (!CollectionUtils.isEmpty(field.getCopyFields())) { CopyFieldDefinition cf = new CopyFieldDefinition(); cf.setSource(field.getName()); cf.setDestination(field.getCopyFields()); addCopyField(cf); } }
public Update buildCreate() { return new AddField(getFieldAttributes()); }
public AddField(Map<String, Object> fieldAttributes, SolrParams q) { super(createRequestParameters(fieldAttributes), q); }
String urlString = "http://localhost:8983/solr/gettingstarted"; SolrClient solr = new HttpSolrClient.Builder(urlString).build(); Map<String, Object> fieldAttributes = new LinkedHashMap<>(); fieldAttributes.put("name", "sell-by"); fieldAttributes.put("type", "tdate"); fieldAttributes.put("stored", true); SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(solr);
public AddField(Map<String, Object> fieldAttributes, SolrParams q) { super(createRequestParameters(fieldAttributes), q); }