5

我正在尝试使用子文档获取父文档。但是出现“嵌套架构时不应发送父过滤器”错误。

在下面附加了我尝试过但我无法得到解决方案的查询

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

下面是我添加到 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()
4

3 回答 3

4

我遇到了同样的错误,并尝试了教程中描述的所有可能性,但后来我发现我managed-schema.xml有一个重复的条目。

自动生成的脚本:

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

我手动添加的另一个:

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

我删除了我的条目,然后它开始正常工作。

于 2019-09-09T07:26:10.530 回答
0

我能够通过将文档标识符类型设置为 来解决此问题_nest_path_,在您的情况下,这似乎是content_type关键。然后在查询中,您不再需要设置fl=*,[child]对我有用的 parentFilter 参数。您仍然可以添加子过滤器,但显然在 Solr8 中,文档存储在层次结构中,不再需要用户识别父级。

我从此处详述的嵌套文档票证中发现了这一点:https ://issues.apache.org/jira/browse/SOLR-12298

于 2019-04-10T16:48:20.217 回答
0

注释掉下面的行对我来说是一个中间解决方案(该行是在你的核心的架构定义中定义的)。

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

通过这段 代码可以找到异常的原因。

(只需 grep 代码中的错误消息“架构嵌套时不应发送父过滤器”。您应该能够查明此异常的来源。)

虽然不太确定逻辑背后的意图/推理

于 2020-04-24T13:04:32.010 回答