Reputation: 504
I'm working with solr5.5.1 and spring-data-solr 1.4.2.RELEASE. I have configured the spring data solr with my working project and working fine. But when i insert data to solr using model class, it automatically update the managed-schema file with relavent field of model class. in this model i'm not using multivalued types, but spring-data-solr update the managed-schema file as multivalued attributes. Why is it happened ? sample field declaration of model class
@SolrDocument(solrCoreName = "car")
public class CarModel{
@Id
@Indexed(type = "string")
private String id;
@Indexed(type = "string")
private String condition;
@Indexed(type = "string")
private String name;
//getters n setters
}
when i save object of this class through SolrCrudRepository
. Then managed-schema will be updated like this,
<field name="condition" type="strings"/>
<field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
<field name="name" type="strings"/>
here fields are multivalued. What is happening here and how can i resolve this ?
Upvotes: 2
Views: 1510
Reputation: 347
I had the same problem, but I tried to use the below suggested implementation. Spring Data Solr: how to set multiValue to false when declaring a field
Also, I have changed the default implementation in solrconfig.xml. I have tlongs to tlong .. etc for all the lst.
<processor class="solr.AddSchemaFieldsUpdateProcessorFactory">
<str name="defaultFieldType">string</str>
<lst name="typeMapping">
<str name="valueClass">java.lang.Boolean</str>
<str name="fieldType">boolean</str>
</lst>
<lst name="typeMapping">
<str name="valueClass">java.util.Date</str>
<str name="fieldType">tdate</str>
</lst>
<lst name="typeMapping">
<str name="valueClass">java.lang.Long</str>
<str name="valueClass">java.lang.Integer</str>
<str name="fieldType">tlong</str>
</lst>
<lst name="typeMapping">
<str name="valueClass">java.lang.Number</str>
<str name="fieldType">tdouble</str>
</lst>
</processor>
I am not sure, if it creates any other problem in future. Now, I am able to see the fields are accepting single value.
Upvotes: 0
Reputation: 9789
I do not believe Spring manages creation of the schema. It assumes all your fields were already defined. So, instead you are hitting creation of the schema using schemaless mode, which is defined in solrconfig.xml.
And schemaless mode creates multiValued fields because it does not know whether the values will be single- or multi-valued over time. So, it errs on the side of caution.
Your best bet is to create the schema you want explicitly either by editing the schema file and reloading, or by using new Admin UI which provides the interface for it.
Or you could modify the schemaless matching definition to create singular fields, but then it will fail if one of them is multivalued. Unless you use patterns to specify which of them should be singular and which multivalued. But by then you might as well declare them directly anyway.
Upvotes: 1