2017-09-14 59 views
0

我在SOLR一些嵌套數據。如何篩選從子文檔特定字段SOLR

{ 
    "name":["Abc"], 
    "age":[30], 
    "hobby":["singing"], 
    "_childDocuments_":[ 
    { 
     "college":["xyz"], 
     "year":[2015], 
     "id":"3752-22491", 
     "3.c.m.c-id":["256939"], 
     "2.c.m-id":["354291"], 
     "path":["3.c.m.ci"]}, 
    { 
     "subject":["history","science"], 
     "marks-1":[75], 
     "marks-2":[75], 
     "id":"3752-802126", 
     "2.c.m-id":["354291"], 
     "path":["2.c.m"]} 
    ]} 

我不是隻得到標記-1標記-2從Solr的。當我搜索時,我發現整個數據都是作爲響應。我只需要幫助獲取這兩個領域。

感謝您的幫助提前。

+0

你能告訴你當前的查詢? – Mysterion

+0

我正在使用這個查詢(http:// localhost:8983/solr/test/select?indent = on&highlight = true&start = 0&rows = 10&wt = json&hl = true&hl.method = unified&fl = *,[child parentFilter = path:1.c childFilter = 「路徑:* C *」 限制= 50] q =名:Abc ) – Learner

回答

0

你不能做到這一點與ChildDocTransformer,因爲它的目的是過濾子文檔顯示,沒有哪個田子文件返回的

而且,我敢肯定,這將是隻是更容易在客戶端或響應的轉化過程中過濾掉這些領域,因爲你不會在限制子文檔領域獲得任何性能改進。

但是,如果你仍然想這樣做,通過Solr的查詢,你應該使用subquery transformer像這樣的東西:

solr/collection_name/select?fl=id,title_t,stars:[subquery] //enter mode for subquery 
&indent=on 
&q=title_t:* // this is the general query, here, just selecting book 
&stars.fl=stars_i // which fields from the child documents to return 
&stars.q={!prefix f=id v=$row.id} // subquery that you need to adapt 

我做的書/評論的收集和這個查詢從here它的工作正好。但是,您需要修改子查詢。這裏的問題是,您只需要選擇與父文檔相對應的特定子文檔。這可能是某種PARENT_ID或別的東西(我沒有看到你的數據信息,所以你會需要它)的。

你爲什麼需要它?否則,每個主文件將包含下面ALL子文檔,你將與子查詢中進行選擇。在我的示例中,我使用前綴查詢,因爲子文檔的id由父文檔的id組成。例如。

id:book1 

和,孩子ID是:

id:book1_r1