簡體   English   中英

在 solr 8 中的 fl 中使用父過濾器時,獲取“當架構嵌套時不應發送父過濾器”

[英]Getting "Parent filter should not be sent when the schema is nested" when using parent filter in fl in solr 8

我正在嘗試使用子文檔獲取父文檔。 但是出現“嵌套架構時不應發送父過濾器”錯誤。

在下面附上我嘗試過的查詢,但我無法得到解決方案

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()

我遇到了同樣的錯誤,並嘗試了教程中描述的所有可能性,但后來我發現我的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_" />

我刪除了我的條目,然后它開始正常工作。

我能夠通過將文檔標識符類型設置為_nest_path_來解決此問題,在您的情況下,這似乎是content_type鍵。 然后在查詢中你不再需要設置 parentFilter 參數只是fl=*,[child]為我工作。 您仍然可以添加子過濾器,但顯然在 Solr8 中,文檔存儲在層次結構中,不再需要用戶識別父級。

我從這里詳述的嵌套文檔票中弄清楚了這一點: https : //issues.apache.org/jira/browse/SOLR-12298

注釋掉以下行作為中間解決方案對我有用(該行在核心的架構定義中定義)。

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

異常的原因可以通過這段代碼查到。

(只是 grep 代碼中的錯誤消息“當架構嵌套時不應發送父過濾器”。您應該能夠查明此異常的來源。)

雖然不太確定邏輯背后的意圖/推理

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM