0

can anybody help me to explain how I can index nested documents? I'am using the lastest version of spring-data-solr , I have a document with a List and annoted as follow:

@Indexed(required = true,stored = true)
@Field(child = true,value = "werkzeuge")
private List<Werkzeug> werkzeuge;

But the document within solr has no field werkzeuge.

Iam using the SOLR schemaless configuration.

Many Thanks,

3 Answers3

1

Nested Document support has been recently added to Spring Data for Apache Solr. At the time of writing there are only snapshot builds for this feature available. Please see DATASOLR-394 and the documentation for details.

Christoph Strobl
  • 6,491
  • 25
  • 33
1

The accepted answer did not work for me so I used a way around. Please know that I am not recommending this solution but this might be helpful for someone with similar case to me.

So, I encoded the nested documents with Base64 encoder and then passed that as a value to Solr. In Spring Boot, there is a Library that allows you to do that.

My Final value that was displayed on Solr was:

profile:["eyJmaXJzdF9uYW1lIjoiaWpheiIsImxhc3RfbmFtZSI6ImFsaSIsIm5hbWVfc3VmZml4IjoiTk9ORSIsImdlbmRlciI6Ik1hbGUiLCJiaXJ0aGRheSI6IjIwMDAtMTAtMjciLCJlbWFpbCI6ImlqYXouYWxpQGlubm92YWRlbHRlY2guY29tIn0"]

While retrieving this value, you simply have to decode this value and you can get your desired value.

Hope this is helpful for anyone.

Eatsam ul haq
  • 317
  • 1
  • 12
0

Many Thanks for the answer and reference to the example project. Now it works for me but it seems that the structure of the nested object is still flat. The Framework generates the root field id but all field are in the same hierarchy. One Example: werkzeug is child of the parent object

{
    "werkzeug_id":"116283s",
    "id_werkzeug":"",
    "werkzeug_zitiernr":"s019910",
    "werkzeug_kyrissnr":"",
    "werkzeug_internnr":"069.02",
    "werkzeug_floerke":"",
    "werkzeug_laenge":0,
    "werkzeug_breite":23,
    "werkzeug_form":"Herz, umrandet",
    "werkzeug_stecher":"",
    "werkzeug_beschriftung":"",
    "werkzeug_image":"s0192202",
    "werkzeug_literatur":"",
    "werkzeug_freitext":"",
    "werkzeug_erfname":"",
    "werkzeug_erfdatum":"2004-12-10T13:11:13Z",
    "werkzeug_korrname":"",
    "werkzeug_publicity":"public",
    "_root_":"205789s"},
  {
    "id":"205789s",
    "all":["205789s"],
    "signatur":"Inc.fol.7541",
    "id_standort":58,
    "sovermerk":"ok",
    "erfdatum":"2004-12-10T14:33:10Z",
    "korrname":"wlb",
    "korrdatum":"Thu Nov 13 13:31:22 UTC 2014",
    "publicity":"public",
    "_version_":1573171122990481408,
    "_root_":"205789s"}]} 

Instead of this it should looks like this?

[
 {id : book1, type_s:book, title_t : "The Way of Kings", author_s : "Brandon 
 Sanderson",
  cat_s:fantasy, pubyear_i:2010, publisher_s:Tor,
  _childDocuments_ : [
    { id: book1_c1, type_s:review, review_dt:"2015-01-03T14:30:00Z",
     stars_i:5, author_s:yonik,
     comment_t:"A great start to what looks like an epic series!"
   }
,
{ id: book1_c2, type_s:review, review_dt:"2014-03-15T12:00:00Z",
  stars_i:3, author_s:dan,
  comment_t:"This book was too long."
  }
 ]}]

Have you any idea what the cause could be ?