0
votes

I want to index nested document. I have a class ProductBean class which has 3 string type fields and one List of type Object.

@Field
String id;
@Field
String tgtKey_;
@Field
String borrowerId;

@Field
List<Car> cars;

Class Car is as follow.

public class Car {
   @Field
   String model;
   @Field
   String cc;

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }
    public String getCc() {
        return cc;
    }
    public void setCc(String cc) {
        this.cc = cc;
    }
}

Below is the code used to index.

    ProductBean bean = new ProductBean("123", "xyz", "23");
    List<Car> cars = new ArrayList<Car>();
    Car c = new Car();
    c.setModel("Pulsar 150");
    c.setCc("150");
    Car c1 = new Car();
    c1.setModel("Desert Strom");
    c1.setCc("500");
    cars.add(c);
    cars.add(c1);
    bean.setCars(cars);
    server.addBean(bean);
    server.commit();

The document is indexed, but data is not correct. I get data as below.

"docs": [
  {
    "id": "123",
    "tgtKey_": "xyz",
    "borrowerId": "23",
    "cars": [
      "com.aiq.solr.poc.Car@25618e91",
      "com.aiq.solr.poc.Car@7a92922"
    ],
    "_version_": 1580777018015875000
  }
]

Any help on this is highly appreciated. I am using Solr 4.10.3

1

1 Answers

0
votes

Unfortunately, the simple support of child=true was added from Solr 5.1.

If you're using old Solr (in your case 4.10.x), you need to use some workaround, which in simple terms should look like this

https://issues.apache.org/jira/browse/SOLR-1945?focusedCommentId=13607635&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13607635

I rather would not copy any code here, but rather will recommend you to migrate to Solr 5.x as soon as possible to prevent this dirty hack.