使用Spring Data Solr将文档索引到特定集合 [英] indexing document to a specific collection using spring data solr

查看:236
本文介绍了使用Spring Data Solr将文档索引到特定集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文档索引到solr中的特定集合.集合名称为程序".我正在使用Spring Data Solr.

I am trying to index a document to a specific collection in solr. The collection name is 'program'. I am using spring data solr.

尝试保存文档时出现以下错误:

I am getting the below error when trying to save the document:

HTTP ERROR 404
Problem accessing /solr/update. 
Reason:Not Found

我的假设是注解@SolrDocument无法识别. spring-data-solr试图将文档发布到/solr/update,而它应该尝试将文档发布到/solr/program/update.但是我不确定如何证明或修复它.

My assumption is that the annotation @SolrDocument is not recognized. spring-data-solr is trying to post the document to /solr/update whereas it should try to post it to /solr/program/update.However I am not sure how to prove it or fix it.

我的架构在以下链接上可用:

My schema is available on the link below:

http://<solr-host>/solr/program/schema

更新请求处理程序可在下面的链接中找到:

The update request handler is available in the link below:

http://<solr-host>/solr/program/update

spring-config-xml

spring-config-xml

<context:annotation-config />
<context:component-scan base-package="com.oostnet.controllers, com.oostnet.models, com.oostnet.services" />
<mvc:annotation-driven />

<solr:solr-server id="solrServer" url="http://<solr-host>/solr" />

<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
    <constructor-arg ref="solrServer" />
</bean>

<solr:repositories base-package="com.oostnet.solr.repositories" />

模型定义:

package com.oostnet.models.documents;

@SolrDocument(solrCoreName="program")
public class Program {

    @Id
    @Indexed
    private String id;
    <more variables>
}

存储库定义:

package com.oostnet.solr.repositories;

public interface ProgramRepository extends SolrCrudRepository<Program, String> {

}

控制器:

package com.oostnet.controllers;

public class ProgramController{
    private ProgramRepository programRepository;
    @Autowired
    public void setProgramRepository(ProgramRepository programRepository) {
        this.programRepository = programRepository;
    }
    public void createProgram(Program program) {
        programRepository.save(program);
    }
}

下面是使用的版本:

<spring.data.solr.version>1.3.2.RELEASE</spring.data.solr.version>
<spring.version>4.1.4.RELEASE</spring.version>
solr server version - solr-spec 4.10.2 

推荐答案

要处理多个集合,您需要在spring配置下启用多个存储库,如下所示:-

To work on multiple collection you need to enable multiple repository under spring configuration as below :-

<context:annotation-config />
<context:component-scan base-package="com.test.solr" />

<solr:solr-server id="solrServer" url="http://localhost:8983/solr" />

<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
    <constructor-arg ref="solrServerFactory" />
</bean>

<solr:repositories base-package="com.test.solr.repositories" multicore-support="true" />
<bean id="solrServerFactory"
    class="org.springframework.data.solr.server.support.MulticoreSolrServerFactory">
    <constructor-arg ref="solrServer" />
    <constructor-arg name="cores">
        <list>
            <value>program</value>
        </list>
    </constructor-arg>
</bean>

这篇关于使用Spring Data Solr将文档索引到特定集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆