Interface for custom field types

DSE Search implements a CustomFieldType interface that marks Apache Solr™ custom field types and provides their actual stored field type. The custom field type stores an integer trie field as a string representing a comma-separated list of integer values. When indexed the string is split into its integer values, each one indexed as a trie integer field. This class effectively implements a multi-valued field based on its string representation.

A CustomFieldType can override this method to provide the FieldType for the binary response writer to look at when it determines whether to call the field’s toObject(). This allows the binary response writer, for example, to return java.util.Date in place of text for a CustomFieldType that extends TrieDateField.

To use the CustomFieldType interface:

  1. Implement a custom field type class.

    To ensure that custom field types control their serialized value, use the getKnownType() method in your CustomFieldType implementation:

    public Class<? extends FieldType> getKnownType()
       {
       return getClass();
       }

    For example:

    package com.datastax.bdp.search.solr.functional;
    
        import com.datastax.bdp.search.solr.CustomFieldType;
        import java.util.ArrayList;
        import java.util.List;
        import org.apache.lucene.index.IndexableField;
        import org.apache.solr.schema.FieldType;
        import org.apache.solr.schema.SchemaField;
        import org.apache.solr.schema.StrField;
        import org.apache.solr.schema.TrieField;
    
        public class CustomTestField extends TrieField implements CustomFieldType
        {
        public CustomTestField()
        {
        this.type = TrieField.TrieTypes.INTEGER;
        }
    
        @Override
        public FieldType getStoredFieldType()
        {
        return new StrField();
        }
    
        @Override
        public boolean multiValuedFieldCache()
        {
        return true;
        }
    
        @Override
        public ListIndexableField createFields(SchemaField sf, Object value)
        {
        String[] values = ((String) value).split(" ");
        ListIndexableField fields = new ArrayListIndexableField();
        for (String v : values)
        {
        fields.add(createField(sf, v));
        }
        return fields;
        }
    
        @Override
        public String toInternal(String value)
        {
        return value;
        }
    
        @Override
        public String toExternal(IndexableField f)
        {
        return f.stringValue();
        }
    
        // Ensures that the custom field type controls its serialized value
        public Class<? extends FieldType> getKnownType()
        {
        return TrieField.class;
        }
    
        }
  2. Export the class to a JAR.

  3. Store the JAR in the appropriate DSE and Solr resources directories for your installation type:

    • Package installations: /usr/share/dse/solr/lib and /usr/share/dse

    • Tarball installations: INSTALL_DIRECTORY/resources/solr/lib and INSTALL_DIRECTORY/resources/dse/lib

    The JAR is added to the CLASSPATH automatically.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use |  Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM