5

I am trying to fetch the parent document with child documents. But getting "Parent filter should not be sent when the schema is nested" error.

Attached the query in below that I have tried but I can't get the solution

q : {!parent which=content_type:person}
fl : *, [child parentFilter=content_type:person]

Below is the document that I have added to solr core.

   Collection<SolrInputDocument> batch = new ArrayList<>();
   // Parent Doc 1, a person mamed John Jones
    SolrInputDocument person1 = new SolrInputDocument();
    person1.addField( "id",            "john_jones" );
    person1.addField( "content_type",  "person"     );
    // "_t" suffix tells Solr that it's text
    person1.addField( "first_name_t",  "John"       );
    person1.addField( "last_name_t",   "Jones"      );
    // states and history used in edismax examples
    person1.addField( "states_t",      "California Nevada Idaho Maine" );
    person1.addField( "history_t",     "safe accident accident accident accident accident" );

    // child docs, the vehicles he owns
    SolrInputDocument p1_car1 = new SolrInputDocument();
    p1_car1.addField( "id",            "jj_car1"    );
    p1_car1.addField( "content_type",  "car"        );
    // For cars "make" is an alias for "manufacturer"
    p1_car1.addField( "make_t",        "Honda"      );
    p1_car1.addField( "model_t",       "Accord"     );

    SolrInputDocument p1_car2 = new SolrInputDocument();
    p1_car2.addField( "id",            "jj_car2"    );
    p1_car2.addField( "content_type",  "car"        );
    p1_car2.addField( "make_t",        "Nissan"     );
    p1_car2.addField( "model_t",       "Maxima"     );

    SolrInputDocument p1_bike1 = new SolrInputDocument();
    p1_bike1.addField( "id",           "jj_bike1"   );
    p1_bike1.addField( "content_type", "bike"       );
    p1_bike1.addField( "make_t",       "Yamaha"     );
    p1_bike1.addField( "model_t",      "Passion"    );

    SolrInputDocument p1_bike2 = new SolrInputDocument();
    p1_bike2.addField( "id",           "jj_bike2"   );
    p1_bike2.addField( "content_type", "bike"       );
    p1_bike2.addField( "make_t",       "Peugeot"    );
    p1_bike2.addField( "model_t",      "Vivacity"   );

    // Add children to parent
    person1.addChildDocument( p1_car1  );
    person1.addChildDocument( p1_car2  );
    person1.addChildDocument( p1_bike1 );
    person1.addChildDocument( p1_bike2 );

    // Add parent to batch
    batch.add( person1 );


    // Parent Doc 2, person mamed Satish Smith
    SolrInputDocument person2 = new SolrInputDocument();
    person2.addField( "id",           "satish_smith" );
    person2.addField( "content_type", "person"       );
    person2.addField( "first_name_t", "Satish"       );
    person2.addField( "last_name_t",  "Smith"        );
    person2.addField( "states_t",     "California Texas California Maine Vermont Connecticut" );
    person2.addField( "history_t",    "safe safe safe safe safe safe safe safe accident" );

    // Vehicles (child docs)
    SolrInputDocument p2_car1 = new SolrInputDocument();
    p2_car1.addField( "id",            "ss_car1"     );
    p2_car1.addField( "content_type",  "car"         );
    p2_car1.addField( "make_t",        "Peugeot"     );
    p2_car1.addField( "model_t",       "iOn"         );
    SolrInputDocument p2_bike1 = new SolrInputDocument();
    p2_bike1.addField( "id",           "ss_bike1"    );
    p2_bike1.addField( "content_type", "bike"        );
    p2_bike1.addField( "make_t",       "Honda"       );
    p2_bike1.addField( "model_t",      "Spree"       );
    // link objects and add to batch
    person2.addChildDocument( p2_car1  );
    person2.addChildDocument( p2_bike1 );
    batch.add( person2 );

    System.out.println( "Adding batch of " + batch.size() + " parent docs" );

    // Submit as a group
    patientSolrClient.add( batch );
    patientSolrClient.commit()
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
Sangeetha
  • 51
  • 4

3 Answers3

4

I was getting same error , and tried all the possibilities described in tutorials, but later i found my managed-schema.xml had a duplicate entry of this.

Auto generated Script:

<fieldType name="_nest_path_" class="solr.NestPathField" 
maxCharsForDocValues="-1" omitNorms="true" omitTermFreqAndPositions="true" stored="false" />

Another one manually added by me:

<fieldType name="_nest_path_" type = "_nest_path_" />

I removed my entry then it started working fine.

B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
vendan
  • 41
  • 5
  • and after that, you need to reload solr to apply changes – user3389 Nov 08 '19 at 16:10
  • 1
    The 2 fields are different. First one is supposed to be 'fieldType'. Second one is supposed to be 'field'. They both serve different purposes. (I checked in the default managed-schema of solr 8.5.1). It's a different thing altogether that commenting out that 'field' makes the query work perfectly fine. The code in https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java has been written in such a way that it forces an exception to be thrown if the field '_nest_path' is found. Not sure about the reasoning of it. – Harshit Apr 24 '20 at 12:55
0

I was able to resolve this issue by setting the document identifier type to _nest_path_, in your case this appears to be content_type key. Then in the query you no longer need to set the parentFilter param just fl=*,[child] worked for me. You can still add child filters but apparently in Solr8 the documents are stored in a hierarchy and no longer require users to identify the parents.

I figured this out from the Nested Document tickets detailed here: https://issues.apache.org/jira/browse/SOLR-12298

0

Commenting out the below line worked for me as an intermediate solution (the line is defined in the schema definition of your core).

<field name="_nest_path_" type="_nest_path_"/>

The reason for the exception can be found out through this piece of Code.

(just grep for the error message "Parent filter should not be sent when the schema is nested" in the code. You should be able to pinpoint the source of this exception.)

Not very sure about the intention/reasoning behind the logic though

Harshit
  • 1,174
  • 1
  • 9
  • 24