spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Duplicate core names in Solr Url in Spring Boot 1.5.1

Open mintster opened this issue 9 years ago • 11 comments

This issue was posted to StackOverflow in this post:

duplicate cores in url sent to solr from spring boot solr data

It describes the Solr Url duplicate core name issue pretty well.

I have encountered the same issue moving to Spring Boot 1.5.1 from 1.4.4 without resolution. The only things I can add to this issue are

  1. This problem occurs with @EnableSolrRepositories multicoreSupport property true or false
  2. @SolrDocument present or not on a Model class makes no difference
  3. Seems when the original SolrServer Url contains the core name ex: http://localhost:8983/solr/corename that core name will be duplicated in the SolrJ URL
  4. I went back several versions of org.apache.solr:solr-core and the problem persists. Like the SO poster I also went to Solr Core 6.3.0 without success. The only fix was going back to Spring Boot 1.4.x.

I plan on staying with v1.5.1 so my only remedy was going with a Solr Embedded configuration until a solution is found.

Thanks!

mintster avatar Feb 18 '17 22:02 mintster

I don't recall any changes to Boot's Solr support in 1.5. Have you tried using a different version of Spring Data Solr? The best was to do that is to override the spring-data-releasetrain.version property. A sample that reproduces the problem would also be useful.

/cc @christophstrobl

wilkinsona avatar Feb 19 '17 07:02 wilkinsona

Andy, thank you for the quick response and the suggestion to override the spring-data-releasetrain.version property. Setting the version to Hopper-SR7 indeed solved my problem, though the Spring Boot 1.5.1 Duplicate Core Name issue in Solr I think still exists.

You asked for a sample that reproduces the problem so I put one together from the Spring Boot Data Solr Sample. You will find that here.

In brief, when you run the tests in the Sample Project you'll see "collection1/collection1" in the url.


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/collection1/collection1/update. Reason:
<pre>    Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>

Thanks!

mintster avatar Feb 19 '17 15:02 mintster

Thanks, @minster

The duplicate collection in the URL is a result of this change in Spring Data Solr.

This looks like a bug in Spring Data Solr to me. @christophstrobl can you please take a look?

wilkinsona avatar Feb 20 '17 12:02 wilkinsona

I've raise DATASOLR-364 for @christophstrobl or someone else from the team to look at. I'll close this since it's not really a Spring Boot issue.

philwebb avatar Mar 01 '17 22:03 philwebb

Sorry for long silence - thanks @mintster for setting up the test project. I've just pushed some changes for DATASOLR-364. Snapshot builds (spring-data-solr:2.2.0.DATASOLR-364-SNAPSHOT) should be available shortly via repo.spring.io in case you want to give them a try.

christophstrobl avatar Mar 02 '17 12:03 christophstrobl

@christophstrobl Any plans to backport to 2.1.x? We can't pick up 2.2.0 in Boot 1.5.x

philwebb avatar Mar 02 '17 19:03 philwebb

@philwebb yes - will be back ported to 2.1.x. but won't be in the Ingalls SR1.

christophstrobl avatar Mar 02 '17 20:03 christophstrobl

I also faced with this issue and spend a lot of time to investigate it. :disappointed: As a temporarily solution the @christophstrobl 's advice works fine for me (build.gradle):

compile('org.springframework.data:spring-data-solr:2.2.0.DATASOLR-364-SNAPSHOT')

Thank you!

w32blaster avatar Mar 24 '17 19:03 w32blaster

hey .. any plans for 2.1.2? this issue blocked me!

valeriucraciun avatar Mar 29 '17 09:03 valeriucraciun

@valeriucraciun DATASOLR-364 has been resolved but there is no release available for us to pick up yet.

philwebb avatar Apr 04 '17 22:04 philwebb

Hi, i encountered with this bug today. I solved it with workaround:

  • first we need to extend class HttpSolrClient with the same simple class name. the Same simple class name is necessary due to logic in org.springframework.data.solr.server.support.SolrClientUtils.clone(T, String).
  • than create bean of our new extended HttpSolrClient in spring application.

the our extended class of HttpSolrClient

package ru.avn;

import java.io.IOException;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;

public class HttpSolrClient extends  org.apache.solr.client.solrj.impl.HttpSolrClient {
    private static final long serialVersionUID = 1973496789131415484L;

    
    public HttpSolrClient(String baseURL,
                          HttpClient client,
                          ResponseParser parser) {
        super(baseURL, client, parser);
    }


    public HttpSolrClient(String baseURL, HttpClient client) {
        super(baseURL, client);
    }


    public HttpSolrClient(String baseURL) {
        super(baseURL);
    }


    @SuppressWarnings("rawtypes")
    @Override
    protected HttpRequestBase createMethod(SolrRequest request,
                                           String collection) throws IOException, SolrServerException {
        String col = (collection != null && baseUrl.endsWith(collection)) ? null : collection;  
        return super.createMethod(request, col);
    }
}

Spring application config

    static final String SOLR_HOST = "solr.host";

    @Resource private Environment environment;

    @Bean
    public SolrClient solrClient() {
        String solrHost = environment.getRequiredProperty(SOLR_HOST);
        return new ru.avn.HttpSolrClient(solrHost);
    }

avn avatar Apr 08 '17 11:04 avn