1

I'm trying to use spring-data-solr:3.0.6 to index data from different source, there is one field, casenumber having different format. When casenumber has ONLY digits, say 123, spring-data-solr will index the field as plong. That not causes problem until later on, a record with casenumber “CASE456”. Solr engine throw error, of course, casenumber must be long

Can I let spring data know "123" is string, not guess it as number without touch schema? I like the schemaless mode. I have tried the following code, spring-data-solr just index “123” as 123. There is little document about @Indexed/type. Thanks

@SolrDocument(collection =..)
public class CaseDocument
{
    @Indexed(type="string")
    private String caseNumber;
    // OR 
    @Indexed(type="lowercase")
    private String caseNumber;
    ....
  • 1
    Those types will only be used if spring generates the schema (i.e. configures Solr) itself. There was [a configuration option for this earlier](https://stackoverflow.com/questions/39791966/enable-schemacreationsupport-in-spring-boot-starter-data-solr) - but it didn't work. I'd try to check if that has been fixed. If you're just submitting the data blindly, the schemaless mode will be used and Solr will guess. The _easiest_ way to fix this is by adding the field to the schema, which should be done in a production setting anyway (either on the Solr side or through spring-data-solr). – MatsLindh Jul 11 '18 at 18:42
  • Thanks so much for sharing. I am going to try spring solr side schema next. – tao.wang.pro Aug 01 '18 at 17:38
  • Curious if you ever solved this problem - we're having a very similar issue, but for a different reason. – Valerie R Jul 19 '19 at 11:31
  • As I learnt solr more, I found schemaless really mean solr can guess schema for you. But solr can guess wrong. So, like MatsLindh said, for production you have to tell solr to interpret data. 1: prefine managed-schema file, declear all as much as you known, if you miss one, at runtime, solr will guess. Again solr can guess wrong. 2: A bit better solution, we use java spring solr data, you can define java bean as SolrDucument, no surprise, the framework will figure out java data type map them to solr type, and write this into managed-schema file. Same thing :) Both works. – tao.wang.pro Jul 25 '19 at 03:59

0 Answers0