Spring Data Solr with dynamic field not working

I am trying to index a document with dynamic fields and define it:

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

    @Field
    String id;

    @Field
    String name;

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

      

And the following repo:

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

      

My solr schema looks like this:

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

      

I am trying to save a new document where the map value is mappedFieldValues:

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

However, I am getting the following exception:

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

      

ERROR: [doc = 5530cbd78b15a5f18dfe3d28] unknown field 'thermometer' on org.apache.solr.client.solrj.impl.HttpSolrServer.request (HttpSolrServer.java:495) at org.apache.solrjp.clientpl request (HttpSolrServer.java:199) at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process (AbstractUpdateRequest.java:118) at org.apache.solr.client.solrj.SolrServer.adver.add (SolrSer 116) at org.springframework.data.solr.core.SolrTemplate $ 4.doInSolr (SolrTemplate.java:178) at org.springframework.data.solr.core.SolrTemplate $ 4.doInSolr (SolrTemplate.java:175) at org.springframework .data.solr.core.SolrTemplate.execute (SolrTemplate.java:132) on org.springframework.data.solr.core.SolrTemplate.saveBean (SolrTemplate.java:175) on org.springframework.data.solr.core.SolrTemplate ...saveBean (SolrTemplate.java:169) at org.springframework.data.solr.repository.support.SimpleSolrRepository.save (SimpleSolrRepository.java:149) at sun.reflect.NativeMethodAccessorImpl.invoke0 (native method) at sun.etrefhod.pl. invoke (NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:601) at org.springframework.data. .support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.executeMethodOn (RepositoryFactorySupport.java:416) at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExeceptorMethodInterceptor. .support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke (RepositoryFactorySupport.java:373) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179) at ) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction (TransactionAspectSupport.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke (TransactionInterceptor.java:voke) (TransactionInterceptor.java:26:29) proceed (ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke (PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAxy207Proxy.java source) com.example.Indexer.indexAll (Indexer.java:29)

So it seems to me that spring-data-solr is incorrectly naming solr with the name of dynamic fields (instead of mappedField_thermometer, it just calls the thermometer).

Any ideas?

+3


source to share


1 answer


Spring data solr supports dynamic field mapping for example, in my project I configured field names for object type

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

      



as you can see any maps of field values ​​on this map. but in your project in solr config you only specified map fields that start with "mappedField_ *", so if you change the field names to mappedField_yourField it will work correctly.

0


source







All Articles