2017-07-08 64 views
0

我試圖下面的數據加載到現有的SOLR使用文件上傳部分Apache Solr實現無法儲存

(6.6)核心嵌套JSON數據
{ 
    "id": "1234", 
    "nationality":"India", 
    "phonenumber":"232323", 
    "personname":"babu rao", 
    "paid":"credi card", 
    "status":"success", 
    "access" :[ 
     {"port":"port1","gate":"Gate1"} 
    ], 
    "approved_by":[ 
     {"name":"appr1","date":"2006-11-30"}, 
     {"name":"appr2","date":"2006-11-30"} 
    ] 
    } 

我這個項目的架構是

<field name="created_date" type="tdate" indexed="true" stored="true" /> 
<field name="passType" type="string" indexed="true" stored="true" /> 
<field name="duration" type="int" indexed="true" stored="true" /> 
<field name="nationality" type="string" indexed="true" stored="true" /> 
<field name="phonenumber" type="string" indexed="true" stored="true" /> 
<field name="personname" type="string" indexed="true" stored="true" /> 
<field name="paid" type="string" indexed="true" stored="true" /> 
<field name="passamount" type="float" indexed="true" stored="true" /> 
<field name="status" type="string" indexed="true" stored="true" /> 
<field name="approved_by" type="string" indexed="true" stored="true" multiValued="true"/> 
<field name="approved_by.name" type="string" indexed="true" stored="true" /> 
<field name="approved_by.date" type="tdate" indexed="true" stored="true" /> 
<field name="access" type="string" indexed="true" stored="true" multiValued="true"/> 
<field name="access.port" type="string" indexed="true" stored="true" /> 
<field name="access.gate" type="string" indexed="true" stored="true" /> 

我收到以下錯誤

Error parsing JSON field value. Unexpected OBJECT_START at [177], 
field=access 

請求您的幫助來解決這個問題。

回答

0

_childDocuments_關鍵需註明在JSON嵌套文件。我已經更新了文檔,現在它將被索引。

{ 
    "id": "1234", 
    "nationality":"India", 
    "phonenumber":"232323", 
    "personname":"babu rao", 
    "paid":"credi card", 
    "status":"success", 
    "_childDocuments_" :[ 
     {"id":456,"port":"port1","gate":"Gate1"}, 
     {"id":786,"name":"appr1","date":"2006-11-30"}, 
     {"id":232,"name":"appr2","date":"2006-11-30"} 
    ] 
    } 

另外您需要更改schema.xml。
[Schema.xml的]

<field name="created_date" type="tdate" indexed="true" stored="true" /> 
<field name="passType" type="string" indexed="true" stored="true" /> 
<field name="duration" type="int" indexed="true" stored="true" /> 
<field name="nationality" type="string" indexed="true" stored="true" /> 
<field name="phonenumber" type="string" indexed="true" stored="true" /> 
<field name="personname" type="string" indexed="true" stored="true" /> 
<field name="paid" type="string" indexed="true" stored="true" /> 
<field name="passamount" type="float" indexed="true" stored="true" /> 
<field name="status" type="string" indexed="true" stored="true" /> 
<field name="name" type="string" indexed="true" stored="true" /> 
<field name="date" type="tdate" indexed="true" stored="true" /> 
<field name="port" type="string" indexed="true" stored="true" /> 
<field name="gate" type="string" indexed="true" stored="true" /> 

更多信息,你可以檢查此文章Yonik: - http://yonik.com/solr-nested-objects/