简体   繁体   中英

Storing Java Object in Schema less solr

Idea:

Convert the POJO into flat map using ObjectToMapTransformer

and form a solrinputdocument from the map and store it in Solr.

While retrieving get the document from the Solr and convert the Document into map and to POJO using MapToObjectTransformer

Problem:

While saving the SolrinputDocument to Solr the flatten key like AB[0].c of the POJO is getting converted to A.B_0_.c in Solr.

This alternate form of storage in Solr makes it difficult to deserialize the solrDocument to POJO.

How to solve this problem? Or what is the alternate way of storing queryable Document in Solr which can be deserialized and serialized easily.

You usually wrap the fields in your POJO with the appropriate Solr fields that you're indexing that field into. See Mapping a POJO for Solr .

If you really want to serialize the complete object into Solr, serialize it into a single field, and if possible, use a string field (as that will store your object directly). If you want to actually search string values inside the object as well, you can use a text field - but since everything is imported into a single field, that'll have a few limitations (like if you want to score different fields or search for values in a single property from the objects).

So: Use the @Field annotation from SolrJ.beans to do specific POJO handling, or mangle it into a single field and search for strings in that field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM