2017-05-07 88 views
0

我有一個需要在Solr中建立索引的JSON文檔。該文件看起來是這樣的:發佈工具和索引處理程序有什麼區別?

{ 
    "id":"1", 
    "prop":null, 
    "path":"1.parent", 
    "_childDocuments_":[ 
     { 
     "id":"2", 
     "path":"2.parent.child" 
     } 
    ] 
} 

它包含_childDocuments_鍵表示父子關係結構。

當我通過後工具,即./bin/post -c coreName data.json插入Solr中的文檔和查詢Solr的,從Solr的話,我得到如下回應:

$ curl 'http://localhost:8983/solr/coreName/select?indent=on&q=*:*&wt=json' 
{ 
    "responseHeader":{ 
    "status":0, 
    "QTime":0, 
    "params":{ 
     "q":"*:*", 
     "indent":"on", 
     "wt":"json"}}, 
    "response":{"numFound":1,"start":0,"docs":[ 
     { 
     "id":"1", 
     "path":["1.parent"], 
     "_childDocuments_.id":[2], 
     "_childDocuments_.path":["2.parent.child"], 
     "_version_":1566718833663672320}] 
    }} 

但是,當我嘗試插入經指數相同的JSON文件處理程序,即curl -

$ curl "http://localhost:8983/solr/coreName/update?commit=true" -H 'Content-type:application/json' --data-binary "@1.json" 
{"responseHeader":{"status":400,"QTime":56},"error":{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.common.SolrException"],"msg":"Unknown command 'id' at [11]","code":400}} 

我得到SolrException。但是,如果我把JSON數組,然後將它顯示了另一種錯誤,即

[{ 
    "id":"1", 
    "prop": null, 
    "path":"1.parent", 
    "_childDocuments_":[ 
     { 
     "id":"2", 
     "path":"2.parent.child" 
     } 
    ] 
}] 

錯誤:

$ curl 'http://localhost:8983/solr/coreName/update?commit=true' -H 'Content-type:application/json' --data "@/home/knoldus/practice/solr/1.json" 
{"responseHeader":{"status":500,"QTime":3},"error":{"trace":"java.lang.NullPointerException\n\tat org.apache.solr.update.processor.AddSchemaFieldsUpdateProcessorFactory$AddSchemaFieldsUpdateProcessor.mapValueClassesToFieldType(AddSchemaFieldsUpdateProcessorFactory.java:370)\n\tat org.apache.solr.update.processor.AddSchemaFieldsUpdateProcessorFactory$AddSchemaFieldsUpdateProcessor.processAdd(AddSchemaFieldsUpdateProcessorFactory.java:288)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldMutatingUpdateProcessor.processAdd(FieldMutatingUpdateProcessor.java:118)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldMutatingUpdateProcessor.processAdd(FieldMutatingUpdateProcessor.java:118)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldMutatingUpdateProcessor.processAdd(FieldMutatingUpdateProcessor.java:118)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldMutatingUpdateProcessor.processAdd(FieldMutatingUpdateProcessor.java:118)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldNameMutatingUpdateProcessorFactory$1.processAdd(FieldNameMutatingUpdateProcessorFactory.java:74)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.FieldMutatingUpdateProcessor.processAdd(FieldMutatingUpdateProcessor.java:118)\n\tat org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)\n\tat org.apache.solr.update.processor.AbstractDefaultValueUpdateProcessorFactory$DefaultValueUpdateProcessor.processAdd(AbstractDefaultValueUpdateProcessorFactory.java:91)\n\tat org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.handleAdds(JsonLoader.java:492)\n\tat org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.processUpdate(JsonLoader.java:139)\n\tat org.apache.solr.handler.loader.JsonLoader$SingleThreadedJsonLoader.load(JsonLoader.java:115)\n\tat org.apache.solr.handler.loader.JsonLoader.load(JsonLoader.java:78)\n\tat org.apache.solr.handler.UpdateRequestHandler$1.load(UpdateRequestHandler.java:97)\n\tat org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:68)\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:166)\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2306)\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:658)\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:464)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:345)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:296)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1691)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:534)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)\n\tat org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)\n\tat java.lang.Thread.run(Thread.java:745)\n","code":500}} 

所以,我必須刪除"prop": null一樣好,甚至使其成爲一個空字符串,如這個:

[{ 
    "id":"1", 
    "prop": "", 
    "path":"1.parent", 
    "_childDocuments_":[ 
     { 
     "id":"2", 
     "path":"2.parent.child" 
     } 
    ] 
}] 

做了這些修改後,我插入了JSON文檔。在Solr通過curl,然後它工作正常。

$ curl 'http://localhost:8983/solr/coreName/update?commit=true' -H 'Content-type:application/json' --data "@/home/knoldus/practice/solr/1.json" 
{"responseHeader":{"status":0,"QTime":851}} 

,我得到以下從Solr的查詢響應:

$ curl 'http://localhost:8983/solr/coreName/select?indent=on&q=*:*&wt=json' 
{ 
    "responseHeader":{ 
    "status":0, 
    "QTime":1, 
    "params":{ 
     "q":"*:*", 
     "indent":"on", 
     "wt":"json"}}, 
    "response":{"numFound":2,"start":0,"docs":[ 
     { 
     "id":"2", 
     "path":["2.parent.child"]}, 
     { 
     "id":"1", 
     "path":["1.parent"], 
     "_version_":1566719240059224064}] 
    }} 

但在這裏我看到的數字差異_childDocuments_已被索引作爲單獨的文檔。

在Solr的數據索引的兩種不同的方法,因此,我有以下問題:

  1. 爲什麼後工具./bin/post沒有索引_childDocuments_單獨像請求處理器/update
  2. 爲什麼請求處理程序/update要求將JSON文檔包裝在數組中?
  3. 最後,爲什麼請求處理程序/update無法處理null值,而Post Tool可以?

回答

0

PostTool是一個小型的Java實用程序,它讀取您輸入的輸入並將其發送到Solr。它不在Solr內部運行。我沒有看過,但我敢肯定:

  1. 沒有檢測childDocuments作爲一個特殊的值,並將它就像任何其他的嵌套JSON
  2. 作爲解釋in the docs,/更新需要數組,你可以發送單個JSON文檔到/更新/ JSON /文檔
  3. PostTool是空轉換爲「」,只是忽略了場
+0

感謝您的快速反應!我通過索引處理程序獲得了索引一個文檔的方式,但爲什麼不通過索引處理程序接受'null'值,這在文檔中沒有提及? – himanshuIIITian

相關問題