Reputation: 479
I'm very new to spring-data SOLR and SOLR, so please forgive me some stupid rookie questions.
Currently I'm creating a spring-boot 1.4.1.RELEASE application, spring-data solr 2.0.3.RELEASE and solr-solrj 5.5.3 together with Java 8.
I'm able to put data into a local SOLR instance, but the data in SOLR do not look like I've expected - maybe I'm expecting wrong?
My data looks like this:
public class Retailer{
/**
* The number of the retailer, unique identifier
*/
@Id
@Indexed
@Field
@NotBlank(message = ValidationConstants.ERROR_MISSING_SAP_RETAILER_NUMBER)
@Column(unique = true)
private String sapRetailerNumber; // NOSONAR
/**
* The company name of the retailer.
*/
@Field
@Indexed
@NotBlank(message = ValidationConstants.ERROR_VALIDATION_MISSING_NAME)
private String name; // NOSONAR
@Field(child=true, value="retailerContact")
@Indexed
@NotNull(message = ValidationConstants.ERROR_VALIDATION_MISSING_CONTACTINFO)
@Valid
private Contact contact;
@Field(child=true, value="retailerAddress")
@Indexed
@NotNull(message = ValidationConstants.ERROR_VALIDATION_MISSING_ADDRESS)
@Valid
private Address address;
}
class Contact:
public class Contact {
@Field
@Indexed
@NotBlank(message = ValidationConstants.ERROR_VALIDATION_MISSING_EMAIL)
@Email(message = ValidationConstants.ERROR_VALIDATION_INVALID_EMAIL, regexp = ValidationConstants.EXPRESSION_RFC5322_MAIL)
private String email; // NOSONAR
@Field
@Indexed
@NotBlank(message = ValidationConstants.ERROR_VALIDATION_MISSING_HOMEPAGE)
private String homepage; // NOSONAR
@Field
@Indexed
private String phone; // NOSONAR
@Field
@Indexed
private String fax; // NOSONAR
}
The class Address is similar to Contact. What I expected is to have structured data in SOLR, but the objects Contact and Address are flattened. As far I found there is a feature called Nested Documents which supports structured data and I hoped to activate this feature by giving the annotation
@Field(child=true, value="retailerContact")
but unfortunately this didn't change anything.
Is there somewhere an spring-data SOLR example using Nested Documents? The example linked in the spring-data SOLR homepage does not seem to use this feature.
Any hint is appreciated, thank you in advance!
Upvotes: 3
Views: 2112
Reputation: 6726
The default MappingSolrConverter
does not yet support nested documents. However you can switch to SolrJConverter
which uses the native mapping.
@Bean
public SolrTemplate solrTemplate(SolrClient client) {
SolrTemplate template = new SolrTemplate(client);
template.setSolrConverter(new SolrJConverter());
return template;
}
Upvotes: 0