Solrj and dynamic fields

I have a solr schema with a dynamic field of different types. For example, in schema.xml there is:

<dynamicField name="*_s" type="string" indexed="true" stored="true"/> <dynamicField name="*_i" type="int" indexed="true" stored="true"/> <dynamicField name="*_l" type="long" indexed="true" stored="true"/> <dynamicField name="*_f" type="float" indexed="true" stored="true"/> <dynamicField name="*_d" type="double" indexed="true" stored="true"/> 

And I want to access these fields using annotated POJO SolrJ. I know that I can have different map links for each data type in POJO, for example:

 ... @Field("*_s") public Map<String, String> strings; @Field("*_i") public Map<String, Integer> integers; ... 

But is it possible to save all dynamic fields on one map? I thought something like:

 ... @Field("*_s") @Field("*_i") public Map<String, Object> dynamicFields; ... 

The only documentation I can find about SolrJ, POJO, and dynamic fields is the old function request: https://issues.apache.org/jira/browse/SOLR-1129

+6
source share
1 answer

I developed a mapping of the "pattern" value in the @Field annotation, which should not match what is in your schema.xml. So, I defined a map in the doc class:

 @Field("*DF") private Map<String, Object> dynamicFields; 

and then in schema.xml dynamic fields have patterns printed with 'DF':

 <dynamicField name="*_sDF" type="string" indexed="true" stored="true"/> <dynamicField name="*_siDF" type="sint" indexed="true" stored="true"/> <dynamicField name="*_tDF" type="date" indexed="true" stored="true"/> 

Now all dynamicFields with different types of values ​​are saved and retrieved using solrServer.addBean (doc) and solrResponse.getBeans (Doc.class). This is with Solr 3.2.0. It has not worked since 1.4 ..

+9
source

Source: https://habr.com/ru/post/889775/


All Articles