In the previous part of my Spring Data Solr tutorial, we learned that Solr provides a REST-like HTTP API which can be used to add information to Solr index and execute queries against indexed data. The problem is that running a separate Solr instance in a development environment is a bit cumbersome.
However, not all hope is lost because Solr provides two alternative server implementations which we can use in our applications. These implementations are described in the following:
- The embedded Solr server connects directly to Solr core. We can use this server for development purposes but we must also remember that using it in production environment is not recommended. However, using the embedded Solr server is still a viable option in the development environment.
- The HTTP Solr server connects to an external Solr server by using HTTP. This is the recommended way of using the Solr search server and that is why we should always use it in the production environment.
This blog entry describes how we can get the required dependencies with Maven. We also learn to configure the Spring Data Solr to use the embedded Solr server in the development environment and the HTTP Solr server in the production environment.
Let's get started.
Getting the Required Dependencies with Maven
We can get the required dependencies with Maven by following these steps:
- Add the Spring Milestone Maven repository to the POM file.
- Add the required dependencies to the pom.xml file.
Both of these steps are described with more details in the following.
Adding the Spring Milestone Maven Repository to the POM File
We can add the Spring milestone Maven repository to our POM file by adding the following XML to the pom.xml file:
<repositories> <repository> <id>spring-milestone</id> <name>Spring Milestone Maven Repository</name> <url>http://repo.springsource.org/libs-milestone</url> </repository> </repositories>
Adding the Required Dependencies to the POM File
We can add the required dependencies to the POM file by following these steps:
- Add the Spring Data Solr dependency (version 1.0.0.RC1) to the dependencies section of our POM file.
- Add the Solr core dependency (version 4.1.0) to the dependencies section of our POM file and exclude the SLF4J JDK14 binding. Because Solr core is required by the embedded Solr server, we can skip this step if we are not using the embedded Solr server.
We can complete these steps by adding the following XML to the dependencies section of the POM file:
<!-- Spring Data Solr --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.0.0.RC1</version> </dependency> <!-- Required by embedded solr server --> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> <version>4.1.0</version> <exclusions> <exclusion> <artifactId>slf4j-jdk14</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency>
Configuring Spring Data Solr
This section describes how we can configure Spring Data Solr to use different Solr servers in the development and production environment. We will use the embedded Solr server in the development environment and the HTTP Solr server in the production environment.
We can configure Spring Data Solr by following these steps:
- Create a properties file.
- Configure the embedded Solr server.
- Configure the HTTP Solr server.
- Set the active bean definition profile.
These steps are described with more details in the following subsections.
Creating the Properties File
The name of our properties file is application.properties and we will use it to configure two properties which are described in the following:
- The solr.server.url property specifies the url of the used Solr server. The value of this property is used to configure the HTTP Solr server which is used in the production environment.
- The solr.solr.home configures the home directory of Solr. The value of this property is used to configure the home directory of the embedded Solr server which is used in the development environment.
The content of the application.properties file looks as follows:
solr.server.url=http://localhost:8983/solr/ solr.solr.home=
Configuring the Embedded Solr Server
This subsection describes how we can configure Spring Data Solr to use the embedded Solr server in the development environment.
Java Configuration
We can create a configuration class which configures the embedded Solr server by following these steps:
- Create a class called EmbeddedSolrContext and annotate that class with the @Configuration annotation.
- Enable Spring Data Solr repositories by annotating that class with the @EnableSolrRepositories annotation and configuring the root package of our Solr repositories.
- Annotate the created class with the @Profile annotation and set its value to 'dev'. This means that this configuration class is bypassed unless the 'dev' profile have been activated.
- Annotate the class with the @PropertySource annotation and set its value to 'classpath:application.properties'. This configures the location of our property file and adds a PropertySource to Spring’s Environment.
- Add an Environment field to the class and annotate that field with the @Resource annotation. The injected Environment is used to access the properties which we added to our properties file.
- Create a method called solrServerFactoryBean() and annotate this method with the @Bean annotation. The implementation of this method creates a new EmbeddedSolrServerFactoryBean object, sets the value of the Solr home and returns the created object.
- Create a method called solrTemplate() and annotate this method with the @Bean annotation. The implementation of this method creates a new SolrTemplate object and passes the used SolrServer implementation as a constructor argument.
The source code of the EmbeddedSolrContext class looks as follows:
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.data.solr.core.SolrTemplate; import org.springframework.data.solr.repository.config.EnableSolrRepositories; import org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean; import javax.annotation.Resource; @Configuration @EnableSolrRepositories("net.petrikainulainen.spring.datasolr.todo.repository.solr") @Profile("dev") @PropertySource("classpath:application.properties") public class EmbeddedSolrContext { @Resource private Environment environment; @Bean public EmbeddedSolrServerFactoryBean solrServerFactoryBean() { EmbeddedSolrServerFactoryBean factory = new EmbeddedSolrServerFactoryBean(); factory.setSolrHome(environment.getRequiredProperty("solr.solr.home")); return factory; } @Bean public SolrTemplate solrTemplate() throws Exception { return new SolrTemplate(solrServerFactoryBean().getObject()); } }
XML Configuration
We can create an XML configuration file for the embedded Solr server by following these steps:
- Configure the used properties file by using the property-placeholder element of the context namespace.
- Enable Solr repositories and configure the base package of our Solr repositories by using the repositories element of the solr namespace.
- Create a bean configuration for the development profile.
- Configure the embedded Solr server bean by using the embedded-solr-server element of the solr namespace. Set the value of the Solr home.
- Configure the Solr template bean. Set the configured embedded Solr server bean as constructor argument.
The contents of the exampleApplicationContext-solr.xml file looks as follows:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:solr="http://www.springframework.org/schema/data/solr" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr.xsd"> <context:property-placeholder location="classpath:application.properties"/> <!-- Enable Solr repositories and configure repository base package --> <solr:repositories base-package="net.petrikainulainen.spring.datasolr.todo.repository.solr"/> <!-- Bean definitions for the dev profile --> <beans profile="dev"> <!-- Configures embedded Solr server --> <solr:embedded-solr-server id="solrServer" solrHome="${solr.solr.home}"/> <!-- Configures Solr template --> <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"> <constructor-arg index="0" ref="solrServer"/> </bean> </beans> <!-- Bean definitions for the prod profile are omitted --> </beans>
Configuring the Http Solr Server
This subsection describes how we can configure Spring Data Solr to use the HTTP Solr server in the production environment.
Java Configuration
We can create a configuration class which configures the HTTP Solr server by following these steps:
- Create a class called HttpSolrContext and annotate that class with the @Configuration annotation.
- Enable Spring Data Solr repositories by annotating that class with the @EnableSolrRepositories annotation and configuring the root package of our Solr repositories.
- Annotate the created class with a @Profile annotation and set its value to 'prod'. This means that this configuration class is bypassed unless the 'prod' profile have been activated.
- Annotate the class with the @PropertySource annotation and set its value to 'classpath:application.properties'. This configures the location of our property file and adds a PropertySource to Spring’s Environment.
- Add an Environment field to the class and annotate that field with the @Resource annotation. The injected Environment is used to access the properties which we added to our properties file.
- Create a method called solrServerFactoryBean() and annotate this method with the @Bean annotation. The implementation of this method create a new HttpSolrServerFactoryBean object, sets the value of the Solr server url and returns the created object.
- Create a method called solrTemplate() and annotate this method with the @Bean annotation. The implementation of this method creates a new SolrTemplate object and passes the used SolrServer implementation as a constructor argument.
The source code of the HttpSolrContext class looks as follows:
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.data.solr.core.SolrTemplate; import org.springframework.data.solr.repository.config.EnableSolrRepositories; import org.springframework.data.solr.server.support.HttpSolrServerFactoryBean; import javax.annotation.Resource; @Configuration @EnableSolrRepositories("net.petrikainulainen.spring.datasolr.todo.repository.solr") @Profile("prod") @PropertySource("classpath:application.properties") public class HttpSolrContext { @Resource private Environment environment; @Bean public HttpSolrServerFactoryBean solrServerFactoryBean() { HttpSolrServerFactoryBean factory = new HttpSolrServerFactoryBean(); factory.setUrl(environment.getRequiredProperty("solr.server.url")); return factory; } @Bean public SolrTemplate solrTemplate() throws Exception { return new SolrTemplate(solrServerFactoryBean().getObject()); } }
XML Configuration
We can create an XML configuration file for the HTTP Solr server by following these steps:
- Configure the used properties file by using the property-placeholder element of the context namespace.
- Enable Solr repositories and configure the base package of our Solr repositories by using the repositories element of the solr namespace.
- Create a bean configuration for the production profile.
- Configure the HTTP Solr server bean by using the solr-server element of the solr namespace. Set the url of the Solr server.
- Configure the Solr template bean. Set the configured HTTP Solr server bean as a constructor argument.
The content of the exampleApplicationContext-solr.xml file looks as follows:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:solr="http://www.springframework.org/schema/data/solr" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/data/solr http://www.springframework.org/schema/data/solr/spring-solr.xsd"> <context:property-placeholder location="classpath:application.properties"/> <!-- Enable Solr repositories and configure repository base package --> <solr:repositories base-package="net.petrikainulainen.spring.datasolr.todo.repository.solr"/> <!-- Bean definitions for the dev profile are omitted --> <!-- Bean definitions for the prod profile --> <beans profile="prod"> <!-- Configures HTTP Solr server --> <solr:solr-server id="solrServer" url="${solr.server.url}"/> <!-- Configures Solr template --> <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate"> <constructor-arg index="0" ref="solrServer"/> </bean> </beans> </beans>
Setting the Active Bean Definition Profile
We can select the active bean definition profile by setting the value of the spring.profiles.active system variable. The allowed values of this system variable (in the context of our example application) are described in the following:
- We can configure our application to run in the development profile by setting the value of the spring.profiles.active system variable to 'dev'.
- When we want configure our application to run in the production profile, we have to set the of the spring.profiles.active system variable to 'prod'.
We can configure our example application to support both profiles by following these steps:
- Add required profiles to the POM file.
- Create the profile specific properties files for system properties.
- Configure the Jetty Maven plugin.
These steps are described with more details in the following.
Adding the Required Profiles to the POM File
We can add the required profiles to our Maven build by following these steps:
- Create a profile for development environment. Set the id of this profile to 'dev' and set the value of the build.profile.id property to 'dev'.
- Create a profile for the production environment. Set the id of this profile to 'prod' and set the value of the build.profile.id property to 'prod'.
The configuration of our Maven profiles looks as follows:
<profiles> <profile> <id>dev</id> <properties> <build.profile.id>dev</build.profile.id> </properties> </profile> <profile> <id>prod</id> <properties> <build.profile.id>prod</build.profile.id> </properties> </profile> </profiles>
Creating the Profile Specific Properties Files for System Properties
The profile specific properties files are located in the sub directories of the profiles directory. The name of each sub directory matches with the values of the build.profile.id properties configured in the pom.xml file.
We can create the profile specific properties files for system properties by following these steps:
- Create a properties file called system.properties to the profiles/dev directory. This properties file contains the system properties of the development profile.
- Create a properties file called system.properties to the profiles/prod directory. This properties file contains the system properties of the production profile.
The content of the properties file used to configure the system properties of the development profile looks as follows:
spring.profiles.active=dev
The content of the properties file used to configure the system properties of the production profile looks as follows:
spring.profiles.active=prod
Configuring the Jetty Maven Plugin
We can configure the Jetty Maven plugin by following these steps:
- Add the plugin declaration of the Jetty Maven plugin to the plugins section of our Pom file.
- Configure the stopKey and stopPort of the Jetty Maven plugin.
- Configure the location of the properties file containing the used system properties.
The configuration of the Jetty Maven plugin looks as follows:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.5.v20120716</version> <configuration> <stopKey>todostop</stopKey> <stopPort>9999</stopPort> <systemPropertiesFile>${project.basedir}/profiles/${build.profile.id}/system.properties</systemPropertiesFile> </configuration> </plugin>
Summary
We have now successfully obtained the required dependencies with Maven and configured Spring Data Solr. This blog entry has taught us four things:
- We learned to get the required dependencies with Maven.
- We know that we should use the embedded Solr server only in the development environment and learned how we can configure Spring Data Solr to use it.
- We learned that we should always use the HTTP Solr server in the production environment and know how we can configure Spring Data Solr to use it.
- We know how we can use the bean definition profiles of Spring Framework for creating different configurations for development and production environment.
The next part of my Spring Data Solr tutorial describes how we can add new document to Solr index, update the information of an existing documents and delete documents from the Solr index.
PS. The example application of this blog entry is available at Github.
HI,
The spring data solr tutorial that you have posted is one of the best I have found on the internet. It is very detailed and comprehensive.
In your spring data solr tutorial you have mentioned "The next part of my Spring Data Solr tutorial describes how we can add new document to Solr index, update the information of an existing documents and delete documents from the Solr index" but I was unable to find continuation to the last part of this tutorial. Please let me know if there is a link to the post that describes how to add new document to solr index...
Would appreciate your response...
Regards,
Kumar
Thank you for the compliment. It is always nice to get positive feedback.
I have not written the next part of this tutorial yet but the example application already has this functionality.
I am planning to write the next part during the weekend and publish it before Monday.
HI Petri,
I'm trying to build and deploy the application at
https://github.com/pkainulainen/spring-data-solr-examples/tree/master/query-methods
but the application context is not getting initialized.. details of error is below.
any help would be appreciated.
java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:52)
at
Update: I removed the irrelevant information - Petri
Hi Matt,
I assume that you use JDK 8. If so, you should use JDK 7 or update the Spring version (and probably other library versions as well).
How to integrate it with Tomcat7?
When the application is deployed to Tomcat, you can specify the active profile by adding the following line to the
conf/catalina.properties
file:spring.profiles.active=dev
Remember that the value of the
spring.profiles.active
property depends from the profile which you want to use.Hi,
Thanks for the response, and also wanted to know like how to index and query html files in a directory using spring-data-solr
Thanks.
The first thing which you have to do is to add the content of these documents to the Solr index. You have two options for doing this:
If you you select option number one, you might want to check out the following resources:
If you select option number two, you have to implement an indexing component which processes the HTML files and adds the indexed text to the Solr index by using Spring Data Solr. You might want to read the next part of my Spring Data Solr tutorial which describes how you can implement a CRUD application with Spring Data Solr.
If you want to learn how you can execute queries against indexed data by using Spring Data Solr, you should read these blog posts:
I hope that this answered to your question.
Hi where is this configuration file..
Which configuration file?
Hi, I can use this search English content,but not Chinese, I use Lucke and I can see all the content has been indexed properly. I want to know whether is my problem of solr configuration or my spring data solr search. My repository just like this:
@Query("name:*?0* or description:*?0* or type:*?0* or mac_address:*?0* or uri:*?0* or attrs:*?0*")
Page find(String keyword,Pageable page);
And I can search my Chinese content just use "*",but can't get anything by using specific Chinese word.
I will be very appreciative if you can give me a hint.Thanks.
Hi,
The query seems to be correct. If the Chinese text is indexed property as you said, the problem can be that
In order to determine the root cause of problem, it would be important that you would answer to the following questions:
As a side note, indexing Chinese seems to be a bit trickier than I originally thought. I found a blog post called Indexing Chinese in Solr which has a brief overview about this. However, that blog post is not very detailed and it would be interesting to find a more comprehensive tutorial about this. If you know any, let me know. :)
I am getting folowwing error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryTodoService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryTodoIndexService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.petrikainulainen.spring.datasolr.todo.repository.solr.TodoDocumentRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
While i am able to run the test cases. Please help me on this. I found this very useful but it is not working for me.
The root cause of this problem is that you have not configured the correct Spring profile for integration tests. If you run the integration tests by using the following command:
mvn clean verify -P integration-test
The correct Spring profile is set by Maven. If you are running the integration tests from your IDE, you have to set the active profile yourself. In other words, you have to add the following line to the JUnit configuration of your IDE:
-Dspring.profiles.active=test
Here are links to webpages which describe how you can do this:
I hope that this answered to your question.
I am getting the error at starting up the jetty. more that there is no web.xml so that i can test the same on tomcat. if i do mvn install it gives no error and runs the tes cases.
The root cause is the same (The correct Spring profile is not set).
If you start Jetty by using a command:
mvn clean jetty:run
, the active profile is set by Maven (I just tested this by running the example application myself).If you are using the standalone Jetty, you have to configure the correct profile manually. In other words, you have to add one of the following lines to the Jetty configuration:
#Add this if you want to use embedded Solr server
-Dspring.profiles.active=dev
#add this if you want to use HTTP Solr server
-Dspring.profiles.active=prod
Check out the chapter 16 of the Jetty user's manual for more details about this.
You can also deploy the created war file to Tomcat 7 because it supports the Servlet 3.0 specification. This comment explains how you can configure the active profile when you are using Tomcat 7.
I hope that this answered to your question.
I am not able to run the jetty server even on dev environment.
How are you trying to run it?
I have solr running on tomcat at 9080. I am running this code through maven jetty. I pointed it to dev environment.
If you want to use the HTTP Solr server, you cannot use the 'dev' profile because it is configured to use the embedded Solr server. In this case, you have to use the 'prod' profile.
Also, since Solr is not running in the default port, you have to set the value of the
solr.server.url
property. You can find this property from the profiles/prod/config.properties file. After this is done, you can run the example application by running the commandmvn clean jetty:run -P prod
at the command prompt (assuming that you are using the schema described in this blog post).If you want to use a standalone server, you have to set the active Spring profile manually. Check out my previous comment for more details about this.
Thanx very much !! it worked as you said.. i needed to point to production.
You are welcome! I am happy to hear that you could solve your problem.
Just want to understand couple of things. What all i need to do to get web.xml
If you want the replace the configuration class (
ExampleApplicationConfig
) with a web.xml file, you can follow these steps:ExampleApplicationConfig
class.DispatcherServlet
configuration to the web.xml file. See the reference manual of Spring Framework for more details about this. Remember to map the dispatcher servlet to the url pattern '/'.ExampleApplicationContext
class.That should do the trick.
Thanx a bunch !!!! I got it.. do you have any default user id and password to access the application...
thanx got it working... thanx for your support and such a nice tutorial..
I guess you figured out that the credentials are user / password :) Anyway, good to hear that I could help you out.
More i am reading and it is getting more interesting to explore.... I got it working in tomcat but now getting error on tomcat....
127.0.0.1 - - [10/May/2013:23:52:48 +0530] "GET /spring%2Ddata%2Dsolr%2Dcriteria/ HTTP/1.1" 200 10580
127.0.0.1 - - [10/May/2013:23:52:48 +0530] "GET /static/css/example.css HTTP/1.1" 404 995
127.0.0.1 - - [10/May/2013:23:52:48 +0530] "GET /static/js/vendor/bootstrap-transition.js HTTP/1.1" 404 1031
all js files are 404 response. while if run the application on jetty it is working
This is a limitation of the example application. The problem is that the static resources are loaded by using absolute paths. That is why they are found only if the web application is found from context path '/'. You have two options for solving this problem:
I hope that this solved your problem.
You rock Petri !!!! i got every thing up and running in my application.
Great!
I decided to update the example application by using option number two. Now the context path is taken into account when static resources are loaded. Thanks for pointing this problem out!
I am using it in application with xmlwebapplication content. Where can I mention to load the HttpSolrContext.java. I am not able to load this java file and hence not any repository.
The example application also has a working XML configuration for Spring application context. The embedded Solr server and the HTTP Solr server are configured in a separate XML file which is imported to the main configuration file by using the
import
namespace element.Read the section called Configuring Spring Data Solr for more details about this.
Thanx Petri !! I successfully integrated it with my project.
You are welcome!
Hi Petri, one question, is it possible to index images... i have requirement to index the profile of users and profile comprises the image also.... any suggestion on this would be great help. Thanx in adnvance.
I have no personal experience from this but it seems that you can extract metadata from different documents by using Apache Tika Apache Tika. Here are links to webpages which might be useful to you:
It seems that it is quite hard to find an exact answer to your question. Unfortunately, I am not able to give it either.
Petri,
The repository link does not have the spring-data-solr jar so its not getting pulled down. I checked their site, and its missing. So any ideas?
Which repository url are you using?
I noticed yesterday that the url http://repo.springframework.org/milestone does not work. Then I checked the homepage of the Spring Data Solr project and noticed that the repository url has changed to http://repo.springsource.org/libs-milestone. After I updated the repository url to the POM files of my Spring Data Solr examples, I could download all the dependencies from Maven repositories.
Thanks, will give it a shot. Would you recommend this approach (spring based model), as I m not sure if Spring is going to be actively working on evolving this solr support.
I am using Spring Data Solr in a production system without any problems. However, it is true that since the Spring Data Solr is not an official Spring project, it might not have as much resources than the official projects. I don't think that this is necessarily a problem but of course you have to make your own mind about this. I can only say that if I had decided to use SolrJ, the codebase of that project would have a lot of boilerplate code. Spring Data Solr makes the code cleaner, shorter and faster to write.
Hi,
1)What is the value of solr.solr.home in :
application.properties :
solr.server.url=http://localhost:8983/solr/
solr.solr.home=
2)where the package in :
@EnableSolrRepositories("net.petrikainulainen.spring.datasolr.todo.repository.solr")
come from ?
Or can it be anything ?
thanks, lot.
Hi Petri,
I cannot get your sample code to run correctly.
The error is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.petrikainulainen.spring.datasolr.todo.repository.solr.TodoDocumentRepository] found for dependency
I am not sure how to resolve this.
Any pointers?
Thank you.
Adil
Have you set the active Spring profile? The example application has two Spring profiles:
If either one of those profiles isn't activated, you get that exception.
If you aren't running the example by using the Maven Jetty plugin (check README), you have to configure the active Spring profile in a such way that it is recognized by the used server.
Which server are you using?
Hi Petri,
The dev profile is in use which is using Jetty. I am using IntelliJ IDE. I invoke the jetty:run goal from the IDE.
The project in use is https://github.com/pkainulainen/spring-data-solr-examples/tree/master/criteria
The only modifications i have done is
1. Setup embedded solr per http://www.petrikainulainen.net/programming/maven/running-solr-with-maven/. I don't think i reach a point where Solr is even started
2. Changed solr version to 4.4.0 in pom.xml
3. Change @Service to @Service("repositoryTodoIndexService") on RepositoryTodoIndexService as i was having similar problem of Spring not resolving the bean
3. Change @Service to @Service("repositoryTodoService") on RepositoryTodoService to resolve the bean for spring
I think is not auto resolving the repositorybean.
Adil
Hi Petri,
I restarted from scratch and setup the project again. This time i used the command line to run the project instead of the intellij
I think the correct command line is
mvn jetty:run -Dspring.profiles.active="dev"
That did work for me and i was able to bootup and navigate to the http url.
Also, Solr 4.4.0 is incompatible. probably changes to the embeddedsolrserver has something to do with this.
The other problem i have is probably a issue in the project.
When i navigate to the home page http://localhost:8983/solr/ ( default url set in the properties file), i am prompted to login. username/password combination is what is specified in your security xml file and when i use that, i see that the login post request is being sent to http://localhost:8983/api/login instead of http://localhost:8983/solr/api/login. Therefore a 404 is always received and 404 view rendered.
i did try changing the security url patterns from /api/login and /api/logout to api/login and api/logout but spring security does not like it
Any ideas on how to resolve that ?
Adil
It is also possible to specify the active Spring profile at command prompt like you did.
However, my example application uses another method. The Maven Jetty plugin used in the example application reads the system properties from a properties file. You can do this by adding the path of the properties file as the value of the
systemPropertiesFile
configuration option like this (add this to the plugin configuration section):About your second problem, the frontend application assumes that the backend is found from the context root. You can fix this adding fixing the urls found from the Javascript files (Seach for the string "/api/" from the directory src/main/webapp/static/js/app).
Hi Petri,
Thank you so much for the help. I was finally able to get it working.
I had to:
- add google guava as maven dependency.
- remove usage of solr:repositories as that was giving me a solr core error. I instead directly created the solr server using the solr home and solr default core properties.
- had to adjust the root context and make it root.
- increase xmx and permgen size
Apologies to have pinged you quite a bit.
Adil
Hi Adil,
It is good to hear that you were able to solve your problem! Don't worry about pinging me. I like to help my fellow developers. That is one reason why I started writing this blog.
How does spring data for solr support or integrate with 'qt' or custom query handlers, especially for read operations.
The "normal" queries made against Solr documents are supported pretty well by following the Spring Data repository abstraction.
Unfortunately, if you want to something "exotic", you might have to create a custom repository implementation. The good news is that you can get access to SolrJ API so you can use it when you need something which isn't supported by Spring Data Solr.
The custom query handlers aren't probably supported out of the box (I haven't checked this project for a while now so this might have changed).
Is it possible to configure two different HTTP Solr servers? or, work with two different collections , this because I'm trying to create two different Repository Interfaces, I'm new in Spring-Solr.
This StackOverflow question explains how you can do that. Unfortunately it is possible only if you create your repositories manually.
Petri
I tried using multicores, got following exception
org.springframework.data.solr.UncategorizedSolrException: Server at localhost:8983/solr returned non ok status:404, message:Not Found; nested exception is org.apache.solr.common.SolrException: Server at localhost:8983/solr returned non ok status:404, message:Not Found
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:110)
at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:144)
at org.springframework.data.solr.repository.support.SimpleSolrRepository.save
(SimpleSolrRepository.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Meth
my solr.xml,
not sure why it's not able to get the core while saving, can you please guide me?
Petri,
Do I have to do something like that,
http://stackoverflow.com/questions/16859181/spring-data-solr-multiple-cores-and-repository
or you have some other solutions ..?
Hi Rupanjan,
for some reason I thought that you followed the answer given at this comment which caused your problem.
Anyway, I haven't been using multiple cores myself so I would say that following the answer of that StackOverflow question is your best option.
I have got following error when i had download a project from github and clean and build one of you project spring data solr - query method.
Netbean 7.4
apache tomcat 7.0.34
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.petrikainulainen.spring.datasolr.todo.repository.solr.TodoDocumentRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
IN exampleApplicationContext-solr.xml
In my scenario, what is my solrHome address.
Hi Binay,
I already answered to this question here.
Dear Petri,
Thank you for response and i really greatful to you.
I have also got the problem after i have done as you said.
In my solrconfig.xml,
4.5
===============================
Apache solr version : 4.5.1
Apache Tomcat : 7.0.41
Though application is running but solr server not starting or running
org.apache.solr.common.SolrException: Could not load config for solrconfig.xml
Caused by: org.apache.solr.common.SolrException: Invalid luceneMatchVersion '4.5', valid values are: [LUCENE_30, LUCENE_31, LUCENE_32, LUCENE_33, LUCENE_34, LUCENE_35, LUCENE_36, LUCENE_40, LUCENE_41, LUCENE_CURRENT] or a string in format 'V.V'
Update: I removed the unnecessary part of the stack trace - Petri
The error message states that the
luceneMatchVersion
'4.5' is not valid. This seems a bit odd because I downloaded the latest Solr distribution (4.5.1) and it uses '4.5' as the value of theluceneMatchVersion
configuration property. Did you download this distribution as well or are you running Solr with Maven?Dear Petri,
I already downloaded the latest Solr distribution (4.5.1). And I follow this Apache Solr 4 Cookbook for Running Solr on Apache Tomcat.I also able to run by manually solr with tomcat. But this won't happen with netbeans after it automatically run tomcat.
I think this is a version error or not
POM
4.1.0
Solr distribution (4.5.1)
But when i tried to update my solr version to 4.5.1 maven couldn't download this
Downloading: http://maven.restlet.org/org/restlet/jee/org.restlet.parent/2.1.1/org.restlet.parent-2.1.1.pom
What is all this problem i'm really don't get it or am i missing something on my configuration . i just want to run my solr on my tomcat and integrate with spring.
Or do i have to go with your "running Solr with Maven".
Hi Binay,
If you use Solr 4.1, you have to set the value of the
luceneMatchVersion
property to '4.1'.I know that this might not be the answer to your problem if you want to use Solr 4.5.1. It seems that the error which you encountered when you tried to use Solr 4.5.1 is a Maven related problem. Maybe the restlet.org Maven repository was down (it seems to be working fine right now), and you could not download the POM file.
Maybe you could try updating the Solr version to 4.5.1 (remember to use the
luceneMatchVersion
'4.5') and see if you can download the missing files.You can, of course, try the example application of my blog post. However, it uses Solr 4.3.X (I should probably update it when I have go time to do it).
Dear Petri,
Thank you for response, I have update the Solr version to 4.5.1 and But I got the following issue.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryTodoIndexService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'todoDocumentRepositoryImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplate' defined in class path resource [net/petrikainulainen/spring/datasolr/config/EmbeddedSolrContext.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.solr.core.SolrTemplate net.petrikainulainen.spring.datasolr.config.EmbeddedSolrContext.solrTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrServerFactoryBean' defined in class path resource [net/petrikainulainen/spring/datasolr/config/EmbeddedSolrContext.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.solr.core.CoreContainer.(Ljava/lang/String;Ljava/io/File;)V
It seems that Spring Data Solr 1.0 supports only Solr 4.3.1. The support for Solr 4.5.1 is added at Spring Data Solr 1.1.0 (no stable release yet). In other words, you can use the the following combinations of Spring Data Solr and Solr:
Dear Petri,
In my solr.home solr.xml contains
and In my /apache-tomcat-7.0.41/conf/Catalina/localhost/solr.xml contains
I have following configuration above for solr and tomcat.All other problem was solved and still got following issue when i run from netbeans however when i start tomcat manually it start both tomcat and solr.
INFO - FileExchangeRateProvider - Reloading exchange rates from file currency.xml
INFO - SolrCore - solr.NRTCachingDirectoryFactory
INFO - SolrCore - [collection1] Opening new SolrCore at /home/binay/solr/collection1/, dataDir=/home/binay/solr/collection1/data/
INFO - JmxMonitoredMap - JMX monitoring is enabled. Adding Solr mbeans to JMX Server: com.sun.jmx.mbeanserver.JmxMBeanServer@3d4c71b1
INFO - SolrCore - [collection1] Added SolrEventListener for newSearcher: org.apache.solr.core.QuerySenderListener{queries=[]}
INFO - SolrCore - [collection1] Added SolrEventListener for firstSearcher: org.apache.solr.core.QuerySenderListener{queries=[{q=static firstSearcher warming in solrconfig.xml}]}
INFO - CachingDirectoryFactory - return new directory for /home/binay/solr/collection1/data
DEBUG - CachingDirectoryFactory - Releasing directory: /home/binay/solr/collection1/data 0 false
INFO - SolrCore - New index directory detected: old=null new=/home/binay/solr/collection1/data/index/
INFO - CachingDirectoryFactory - return new directory for /home/binay/solr/collection1/data/index
DEBUG - CachingDirectoryFactory - Releasing directory: /home/binay/solr/collection1/data/index 0 false
INFO - SolrCore - [collection1] CLOSING SolrCore org.apache.solr.core.SolrCore@326b75b0
INFO - SolrCoreState - Closing SolrCoreState
INFO - DefaultSolrCoreState - SolrCoreState ref count has reached 0 - closing IndexWriter
INFO - SolrCore - [collection1] Closing main searcher on request.
INFO - CachingDirectoryFactory - Closing NRTCachingDirectoryFactory - 2 directories currently being tracked
DEBUG - CachingDirectoryFactory - Closing NRTCachingDirectoryFactory - currently tracking: CachedDir<>
DEBUG - CachingDirectoryFactory - Closing NRTCachingDirectoryFactory - currently tracking: CachedDir<>
DEBUG - CachingDirectoryFactory - Closing directory when closing factory: /home/binay/solr/collection1/data
INFO - CachingDirectoryFactory - looking to close /home/binay/solr/collection1/data [CachedDir<>]
INFO - CachingDirectoryFactory - Closing directory: /home/binay/solr/collection1/data
DEBUG - CachingDirectoryFactory - Closing directory when closing factory: /home/binay/solr/collection1/data/index
INFO - CachingDirectoryFactory - looking to close /home/binay/solr/collection1/data/index [CachedDir<>]
INFO - CachingDirectoryFactory - Closing directory: /home/binay/solr/collection1/data/index
DEBUG - CachingDirectoryFactory - Removing from cache: CachedDir<>
DEBUG - CachingDirectoryFactory - Removing from cache: CachedDir<>
ERROR - CoreContainer - Unable to create core: collection1
org.apache.solr.common.SolrException
at org.apache.solr.core.SolrCore.(SolrCore.java:834)
at org.apache.solr.core.SolrCore.(SolrCore.java:625)
at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:522)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:557)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:247)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:239)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.nio.channels.OverlappingFileLockException
at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1056)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:1154)
at org.apache.lucene.store.NativeFSLock.obtain(NativeFSLockFactory.java:217)
at org.apache.lucene.store.NativeFSLock.isLocked(NativeFSLockFactory.java:319)
at org.apache.lucene.index.IndexWriter.isLocked(IndexWriter.java:4245)
at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:480)
at org.apache.solr.core.SolrCore.(SolrCore.java:755)
... 11 more
ERROR - CoreContainer - null:org.apache.solr.common.SolrException: Unable to create core: collection1
at org.apache.solr.core.CoreContainer.recordAndThrow(CoreContainer.java:934)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:566)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:247)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:239)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.solr.common.SolrException
at org.apache.solr.core.SolrCore.(SolrCore.java:834)
at org.apache.solr.core.SolrCore.(SolrCore.java:625)
at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:522)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:557)
... 8 more
Caused by: java.nio.channels.OverlappingFileLockException
at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1056)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:1154)
at org.apache.lucene.store.NativeFSLock.obtain(NativeFSLockFactory.java:217)
at org.apache.lucene.store.NativeFSLock.isLocked(NativeFSLockFactory.java:319)
at org.apache.lucene.index.IndexWriter.isLocked(IndexWriter.java:4245)
at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:480)
at org.apache.solr.core.SolrCore.(SolrCore.java:755)
... 11 more
Hi Binay,
You cannot add XML to Wordpress comments because Wordpress removes from them before it saves the comment to the database. Anyway, since you can run Tomcat manually, I think that your configuration is fine.
This seems like a Netbeans related problem. Unfortunately I have not used Netbeans for four years so I have no idea how you could solve this problem.
Are you sure that another hasn't obtained the file lock when you start Tomcat from Netbeans?
Hello Petri,
the lack of documentation about Spring Data Solr is really frustrating. Thank you for your time!
I've followed your blog and tried to add Spring Data Solr functionality to my GWT application, which already worked with Solr through Solrj.
In my case repository and service are not injected and are always null. I tried both @Resource and @Autowired annotations.
I described the problem here: http://stackoverflow.com/questions/20198354/injecting-spring-data-solr-repository-always-returns-null
Hi Konstantin,
I have never used GWT but I assume that this is not a Spring Data Solr related problem because you cannot inject your service either. How did you integrate Spring and GWT?
Hii,, I also use gxt over gwt, I tried your tutorial works well. but when I used gwt emulator the service had a problem like this ..
Cannot resolve reference to bean 'solrTemplate' while setting bean property 'solrOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplate' defined in class path resource [application-context-solr.xml]: Cannot resolve reference to bean 'solrServer' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrServer': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.http.impl.conn.SchemeRegistryFactory.createSystemDefault()Lorg/apache/http/conn/scheme/SchemeRegistry;:
I know, the problem is how to configure with gwt emulator works with spring data solr. But I don't know how to resolve this, could you help me some clue ?,
Thanks
It seems that the static
createSystemDefault()
method of theSchemeRegisterFactory
class isn't found. This class belongs to the Apache HttpClient library. Which version of Apache HttpClient are you using? Is it possible that the GWT emulator uses another version of this library which doesn't have this method?Thanks Petri, I'm using maven with spring data solr 1.0.0. I have check that the dependency has httpclient from apache http component version 4.2.2. I have try to exclude that the dependency to avoid conflict with existing dependency if any. I also try to search another dependency on my project to ensure there is only one httpclient dependency. Still not working ;(
I'm sory, I'm forget. I use the unit test using mockito like your example works well without emulator,
Hi,
If the example works fine when you don't use the GWT emulator, the problem is that that the emulator probably loads an incompatible version of the Apache HttpClient library. Can you see which version of the Apache HttpClient library is used by the GWT emulator?
Have tried to resolve this conflict by using the dependency tree?
Yes, I have check it, everything it's ok, Only spring data using httpclient from org.apache.httpcomponents artifact, hmmm , but I'm using common lang 2.6 on this project. Spring data using commons lang3, is it the problem ?
The dependencies of your project are probably just fine.
Can you add a link to the website of the GWT emulator? I tried to google it but since I have no experience from GWT, I am not sure which search result is the correct one. Thus, it is probably best to ask this from you.
how to connection hadoop/share/hadoop/httpfs/tomcat with solr in ubuntu
Hi,
Could you provide a more detailed description of your problem?
Hello,
I have configured the Spellchecker successfully.
Now can you guide me how can i use the suggestions by @Query ?
Thanks,
Ankur
Hi Ankur,
I answered to this question here.
Hello
Im trying to setup two different solrTemplates beans (solrTemplateA and solrTemplateB) in my xml context file, and injecting them in their corresponding repository but I'm getting the following error when loading the application context:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplateA': Cannot resolve reference to bean 'solrTemplate' while setting bean property 'solrOperations'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'solrTemplate' is defined
The temaplates are config as
And in the repository I inject the template as following:
@Resource(name = "deviceEventsSolrTemplate")
SolrTemplate deviceEventsSolrTemplate;
Do you have any idea of how this problem can be solved?
Thanks in advance for you help
Hi,
I haven't run into this problem myself but I did found this StackOverflow question which could help you out. To be more specific, this answer describes how you can create multiple
SolrTemplate
beans.Let me know if this did the trick.
Hi Petri
I really like your spring solr data tutorial and I have learned a lot. But now I am running into an issue, infact 2 issues any help will be really appreciated.
1. I have a Solr Document that i want to save. That Solr document has another object in it that I have created. When i try to save the document, solr does not save the data that emebbed object had.
2. Same is happening with Map. Infaact in 1. atleast that object was storing the toString() value of the object so I could see the field for eg: Object had a field name data_txt(where _txt is wild card entry for multivalues) but in case of Map it does not even show that.
can you please help
Hi Sachin,
here are some answers to your questions:
Map
objects to Solr index (I have saved lists of "simple" objects to multivalued fields) and the weird thing is that I couldn't find anything interesting from Google either. That is why I have to assume that you cannot do this.Hi i have configured solr with 3 node cluseter , and trying to import the data from hbase tables for that i have used , dataimport handler, but i'm getting below error after startup tomcat ,
i removed write.lock file in collection1/data/folder and restarted but still same issue, can u please help
Hi,
You might want to check out this answer to a similar StackOverflow question. It proposes some solutions to your problem.
Hi, first of all thanks for these great posts!
As I described at: http://stackoverflow.com/questions/27719737/solr-xml-and-schema-xml-of-embedded-solr-on-spring-data-solr
I'm confused with embedded solr. Following your steps, when Spring tries to create the embeddedSolr I get: Caused by: java.io.IOException: Can't find resource 'solrconfig.xml'
Must be a solrconfig.xml? and a schema.xml too?
Hi,
This blog post assumes that you have created a "local Solr installation" by following the instructions given in this blog post.
If you have some further questions, don't hesitate to ask them!
Hi Petri! Thanks a lot for the article!
You said: "The embedded Solr server connects directly to Solr core". Could you please said how Solr server knows what exact core to connect to?
In my case I have a core named "mycore". In the logs (truncated) I see:
Found core "mycore" in c:\solr\example\solr\mycore\
Found 1 core definitions
new SolrResourceLoader for directory: 'c:\solr\example\solr\mycore\'
Loaded SolrConfig: solrconfig.xml
Opening new SolrCore at c:\solr\example\solr\mycore\, dataDir=C:\solr\example\solr\mycore\data\
registering core: mycore
But once I perform a search in the repository, I get:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.data.solr.UncategorizedSolrException: No such core:
How to define the core if I want to use the one named "mycore"? Thank you.
PS: All works good with the prod profile.
A bit more details:
[1] The code:
@Bean
public EmbeddedSolrServerFactoryBean solrServerFactoryBean() {
final EmbeddedSolrServerFactoryBean factory = new EmbeddedSolrServerFactoryBean();
factory.setSolrHome("c:/solr/example/solr/");
System.out.print("");
for (final String core : factory.getCores()) {
System.out.println(core);
}
System.out.println("");
return factory;
}
Gives: ""
[2] The code:
@Bean
public SolrTemplate solrTemplate() throws Exception {
return new SolrTemplate(solrServerFactoryBean().getSolrServer("mycore"));
}
Gives:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.core.SolrTemplate]: Factory method 'solrTemplate' threw exception; nested exception is java.lang.IllegalArgumentException: Resource location must not be null
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 65 more
Caused by: java.lang.IllegalArgumentException: Resource location must not be null
Hi Maksim,
I assume that it reads the core configuration from the
solr.xml
file that is found from the home directory of the local Solr instance (the value of thesolr.solr.home
property).I have tested this with a Solr instance that was created by following the instructions given in this blog post: Running Solr with Maven. However, I have to admit that I haven't tested this with the latest Spring Data Solr version. Which version of Spring Data Solr are you using?
Petri, thanks for your help!
In my case I use spring-boot 1.2.1, org.springframework.data:spring-data-solr 1.3.1, org.apache.solr:solr-core 4.10.3, org.apache.solr:solr-solrj 4.10.3.
and I have just a sample solr.xml that is supplied with Solr distribution. It contains only default contents (no specific core):
${host:}
${jetty.port:8983}
${hostContext:solr}
${zkClientTimeout:30000}
${genericCoreNodeNames:true}
${socketTimeout:0}
${connTimeout:0}
Hi Maksim,
The configuration that is described in this blog post should work with your Spring Data Solr and Solr versions. Also, it seems that Wordpress stripped the XML tags from your
solr.xml
file, but I assume that the problem is that you are trying to use the Solr example application (I have never been able to get it to work properly with the embedded Solr server).Does your application work if you create your Solr instance by following the instructions given in this blog post (If you are in a hurry, you can get the Maven project from Github)?
Petri, it's started working!
You're absolutely right the problem was with solr.xml. The one that I used was copied from SourCloud distribution. This did not contain the "cores" section at all. Like you suggested I referred to the blog post http://www.petrikainulainen.net/programming/maven/running-solr-with-maven/ and got solr.xml from there. After I adjusted the core names in the solr.xml and restarted my project, the magic happened! Thanks a lot for your contribution!
Hi,
Thanks for this tutorial.
In my environment, we have multiple nodes on solr. Is this possible to get the consolidated data from nodes.
In this example, we are executing the query in one node.
Can i execute the query from solr instead of direct call to riak ?
Thanks,
Deepak
Hi,
Spring Data Solr has a some kind of support for multiple cores, but unfortunately it seems that the
MulticoreSolrServerFactory
class supports only multiple cores found from a single Solr server.However, I found one blog post that might be helpful to you. It explains how you can use multiple cores in a single web application when you use the "manual way". I hope that it helps you to solve your problem.
That blog post solution is not working...
Hi,
That's unfortunate. It's a shame that I haven't used multiple cores => I don't know how you can use them with Spring Data Solr.
Is there anyway one can see the lucene query that spring data solr translates and sends to the solr server ?
If I remember correctly, Spring Data Solr writes the Lucene query to the log file by using either the DEBUG or TRACE log level. However, because I haven't used Spring Data Solr for a while, it is possible that I am wrong about this.
Hi,Petri.
I think I need your help.I post the problem in the solr encoded problem.And I don't konw how to fix it.the English is fine but not chinese
Thanks,
Hong.
I would love to help you but I have never indexed Chinese with Solr. However, I have one question for you: do you use the same tokenizer when you add Chinese into your Solr index and when you query information from it?
schema.xml as follow:
I add the jar that describe in \contrib\analysis-extras\README.TXT to \lib.and it seem no problems when the application start up.
the messages in the console are:
DEBUG - AbstractPluginLoader - created : org.apache.lucene.analysis.cn.smart.SmartChineseSentenceTokenizerFactory
DEBUG - AbstractPluginLoader - created : org.apache.lucene.analysis.cn.smart.SmartChineseWordTokenFilterFactory
DEBUG - IndexSchema - field defined: title{type=text_general,properties=indexed,tokenized,stored,required, required=true}
then I really don't konw how to deal with it.somethings wrong with the schema.xml ?Thank you,Petri .
the schema.xml is no present in the page.I use config inside the index and query analyzer.The tokenizer in index and query analyzer is solr.SmartChineseSentenceTokenizerFactory .I think the tokenizer is the same.
Unfortunately there are only a few HTML tags that can be used in comments. That is why you cannot paste XML into your comment (or you can, but Wordpress removes it).
Hi Petri.I know my problem.It is because I use the conditions = new Criteria(ProductDocument.FIELD_TITLE).contains() method which lead to a query like q=title%3A*%E8%BD%A6%E8%BD%A6%E8%BD%A6* .There are two wildcards in the query.But when I replace contains with conditions = new Criteria(ProductDocument.FIELD_TITLE).is() method ,query is q=title%3A%E8%BD%A6%E8%BD%A6%E8%BD%A6 that without two wildcards there ,and I get the results.So that is my problem.I sorry waste your time to see my own mistakes, I should careful to analysis the question ,I really know little about the tool before I start to use it.Thank you.
Hi Hong,
It is great to hear that you were able to solve your problem! Also, there is no need to apologize. I love solving problems and to be honest, you didn't waste a lot of my time. Besides, everyone makes mistakes and sometimes it's quite hard to spot them.
Keep up the good work.
Hi, I am getting thus exception in starting the hybris server
: getting error creating bean with name defaultsolesercerservice defined in class path resource global-solrserver-spring.XML.invocation of init method failed. error while executing sole start command for instance name default, host name, localhost, port 8983
This exception comes when u start Hybris server or solr server
issue is with bean here..as it says error while creating a bean..
any idea fir solution to thus above Erie
.Would appreciate a quick solution
Hi,
First, I am sorry that it took me so long to answer to your comment. About your problem: Unfortunately I don't know what your problem is because you didn't provide the full stack trace. If you happen to see my answer, can you provide the full stack trace so that I can take a look at it?