动态字段不起作用的Spring Data Solr

时间:2015-04-23 16:42:10

标签: java spring solr spring-data spring-data-solr

我正在尝试使用动态字段索引文档并定义它:

@SolrDocument(solrCoreName = "collection1")
public class SolrProduct {

    @Field
    String id;

    @Field
    String name;

    @Field("mappedField_*")
    Map<String, List<String>> mappedFieldValues;
}

以下回购:

public interface SolrProductRepository extends SolrCrudRepository<SolrProduct, String> { }

我的solr架构如下:

<field name="name" type="text_ws" indexed="true" stored="true"/>
<dynamicField name="mappedField_*" type="text_general" indexed="true" stored="true"/>

我正在尝试保存一个新文档,其中mappedFieldValues Map的值为:

  

{thermometer = [yes],camera = [yes],vibration = [Motion],brand = [Philips]}

然而,我得到以下例外:

org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:
     

错误:[doc = 5530cbd78b15a5f18dfe3d28]未知字段&#39;温度计&#39;         在org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:495)         在org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:199)         在org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:118)         在org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)         在org.springframework.data.solr.core.SolrTemplate $ 4.doInSolr(SolrTemplate.java:178)         在org.springframework.data.solr.core.SolrTemplate $ 4.doInSolr(SolrTemplate.java:175)         在org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:132)         在org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:175)         在org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:169)         在org.springframework.data.solr.repository.support.SimpleSolrRepository.save(SimpleSolrRepository.java:149)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         在java.lang.reflect.Method.invoke(Method.java:601)         at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:416)         at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:401)         at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:373)         在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)         at org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:99)         at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)         在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)         at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)         在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)         在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)         在$ Proxy60.save(未知来源)         在com.example.Indexer.indexAll(Indexer.java:29)

所以在我看来,spring-data-solr没有用动态字段名称正确调用solr(而不是mappedField_thermometer,它只是调用温度计)。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Spring数据solr支持动态字段映射 例如,在我的项目中,我已将任何字段名称配置为对象类型

@org.springframework.data.solr.core.mapping.Dynamic
@org.apache.solr.client.solrj.beans.Field("*")
private ListOrderedMap<String, Object> fieldValueMap;

因为您可以看到任何字段值映射到此映射。 但是在你的solr配置项目中,你只说了以“mappedField_ *”开头的地图字段,所以如果你将字段名改为mappedField_yourField它就能正常工作