solr How to create a custom fieldType Create a custom Solr field type from own custom Java class

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


Schema changes:

You will need to define a new field type in your solr schema file and then you can create fields of that type. Example schema snippet:

<!-- Source: solr/example/.../conf/schema.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="adam" version="1.3">
    <fieldType name="rank_t" class="org.apache.solr.schema.ext.RankFieldType"/>
   <field name="rank" type="rank_t" indexed="true" stored="true"/>

Java class for custom field type:

// Source: src/java/org/apache/solr/schema/ext/
package org.apache.solr.schema.ext;


import org.apache.lucene.document.Fieldable;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;

public class RankFieldType extends FieldType {

    public SortField getSortField(SchemaField field, boolean top) {
        return new SortField(field.getName(), new RankFieldComparatorSource(), top);

    // copied verbatim from GeoHashField method
    public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
         writer.writeStr(name, f.stringValue(), false);

Got any solr Question?