3

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!

Samundra
  • 1,869
  • 17
  • 28
flexguse
  • 479
  • 6
  • 22
  • I tried both 2.0.3 and 2.0.5 SpringBoot but unfortunatelly without success. We missed something important that I suppose was not detailed described on any tutorials. BTW Section about child document using has a couple of paragraphs info on official reference docs page. I suppose it is because nobody uses Spring data solr in general – Bogdan Samondros Oct 05 '18 at 17:41

1 Answers1

0

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;
}
Christoph Strobl
  • 6,491
  • 25
  • 33
  • 1
    Unfortunately the SolrJConverter did not the trick. I added you code snippet to my test configuration, but nothing changed in the way the data is put into solr. Is somewhere a fully functional demo application I can use as a template? Just to ensure I did not do any misconfiguration. – flexguse Oct 04 '16 at 15:36
  • @flexguse Any success ? – Root Nov 07 '18 at 08:16
  • @Root the project is more than 2 years old and I'm no more working on it – flexguse Nov 07 '18 at 21:14
  • The mystery continues... – Eatsam ul haq Dec 14 '22 at 15:26