I am doing a simple Search exercise in solr. I followed this tutorial. http://www.baeldung.com/spring-data-solr
I did all same. I run the test case I am getting an error like this:
<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/categories/categories/update. Reason:
<pre> Not Found</pre></p>
</body>
</html>
; nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/categories: Expected mime type application/octet-stream but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
I am not able to understand why it taking /solr/categories/categories/update two times categories. My Categories class look like this:
My configurations: pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject-webapi</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<!-- <relativePath /> lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<!-- <version>3.0.3.RELEASE</version> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@SolrDocument(solrCoreName = "categories")
public class Category {
@Id
@Indexed(name = "id", type = "string")
private String id;
@Indexed(name = "category", type = "string")
private String category;
@Indexed(name = "category", type = "string")
private String categoryId;
@Indexed(name = "divId", type = "string")
private String divId;
}
My Application.java
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Import({ SolrConfig.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Configuration
@EnableSolrRepositories(basePackages = "com.myproject.webapi.solr.repository", namedQueriesLocation = "classpath:solr-named-queries.properties", multicoreSupport = true)
public class SolrConfig {
@Bean
public SolrClient solrClient() {
return new HttpSolrClient("http://localhost:8983/solr");
}
@Bean
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
return new SolrTemplate(client);
}
}
My SolrConfig.java
@Configuration
@EnableSolrRepositories(basePackages = "com.myproject.webapi.solr.repository", namedQueriesLocation = "classpath:solr-named-queries.properties", multicoreSupport = true)
public class SolrConfig {
@Bean
public SolrClient solrClient() {
return new HttpSolrClient("http://localhost:8983/solr");
}
@Bean
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
return new SolrTemplate(client);
}
}
My Repository class:
public interface CategoryRepository extends SolrCrudRepository<Category, String> {
public List<Category> findByCategoryId(String categoryId);
public List<Category> findByCategory(String category);
@Query("id:*?0* OR name:*?0*")
public Page<Category> findByCustomQuery(String searchTerm, Pageable pageable);
@Query(name = "Category.findByNamedQuery")
public Page<Category> findByNamedQuery(String searchTerm, Pageable pageable);
}
My Unit Test class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SolrConfig.class)
public class CategoryRepositoryIntegrationTest {
@Autowired
private CategoryRepository categoryRepository;
@Before
public void clearSolrData() {
categoryRepository.deleteAll();
}
@Test
public void whenSavingCategory_thenAvailableOnRetrieval() throws Exception {
final Category category = new Category();
category.setId("P000089998");
category.setCategory("OLD_COMS_FOOD");
category.setCategoryId("9989999");
category.setDivId("75");
categoryRepository.save(category);
final Category retrievedCategory = categoryRepository.findOne(category.getId());
assertEquals(category.getId(), retrievedCategory.getId());
}
categories
- somewhere where it shouldn't be included it has been added - usually in the URL used to point to the core – Head