2015-12-09 134 views
1

我有以下的JSON結構:嵌套JSON在彈性搜索不被拾起

{ 
    "Dataset": "kh_offers", 
    "Instance": "20140817", 
    "Record": [{ 
     "45": "{\"errorCode\":null,\"runStatusId\":null,\"lakeHdfsPath\":\"/user/jmblnvr/20140817_011500_zoot_kohls_offer_init.dat\",\"fieldIndex\":45,\"datasetFieldName\":\"PRESENTABLE_FLAG\",\"datasetFieldSum\":0.0,\"datasetFieldMin\":0.0,\"datasetFieldMax\":0.0,\"datasetFieldMean\":0.0,\"datasetFieldSigma\":0.0,\"datasetFieldNullCount\":0.0,\"datasetFieldObsCount\":0.0,\"datasetFieldKurtosis\":0.0,\"datasetFieldSkewness\":0.0,\"frequencyDistribution\":\"(T,170544)\",\"id\":null,\"fieldType\":\"STRING\"}" 
    }, { 
     "30": "{\"errorCode\":null,\"runStatusId\":null,\"lakeHdfsPath\":\"/user/jmblnvr/20140817_011500_zoot_kohls_offer_init.dat\",\"fieldIndex\":30,\"datasetFieldName\":\"FIRST_PYMT_DATE\",\"datasetFieldSum\":0.0,\"datasetFieldMin\":0.0,\"datasetFieldMax\":0.0,\"datasetFieldMean\":0.0,\"datasetFieldSigma\":0.0,\"datasetFieldNullCount\":0.0,\"datasetFieldObsCount\":0.0,\"datasetFieldKurtosis\":0.0,\"datasetFieldSkewness\":0.0,\"frequencyDistribution\":null,\"id\":null,\"fieldType\":\"STRING\"}" 
    }] 
} 

我很奇怪,爲什麼彈性搜索無法處理這種嵌套結構?是不是因爲怪異\,使得它時,我的作家是寫它有效的JSON?是否有其他原因?

彈性搜索正在加速前3場,但是當我深入到記錄它只是想串的一個質量塊。

回答

1

你在把它當作一個字符串,因爲你已經用引號包圍它,並逃脫「內部」引號。只需傳入JSON即可:

{ 
    "Dataset": "kh_offers", 
    "Instance": "20140817", 
    "Record": [{ 
     "45": { 
      "errorCode": null, 
      "runStatusId": null, 
      "lakeHdfsPath": "/user/jmblnvr/20140817_011500_zoot_kohls_offer_init.dat", 
      "fieldIndex": 45, 
      "datasetFieldName": "PRESENTABLE_FLAG", 
      "datasetFieldSum": 0.0, 
      "datasetFieldMin": 0.0, 
      "datasetFieldMax": 0.0, 
      "datasetFieldMean": 0.0, 
      "datasetFieldSigma": 0.0, 
      "datasetFieldNullCount": 0.0, 
      "datasetFieldObsCount": 0.0, 
      "datasetFieldKurtosis": 0.0, 
      "datasetFieldSkewness": 0.0, 
      "frequencyDistribution": "(T,170544)", 
      "id": null, 
      "fieldType": "STRING" 
     } 
    }, { 
     "30": { 
      "errorCode": null, 
      "runStatusId": null, 
      "lakeHdfsPath": "/user/jmblnvr/20140817_011500_zoot_kohls_offer_init.dat", 
      "fieldIndex": 30, 
      "datasetFieldName": "FIRST_PYMT_DATE", 
      "datasetFieldSum": 0.0, 
      "datasetFieldMin": 0.0, 
      "datasetFieldMax": 0.0, 
      "datasetFieldMean": 0.0, 
      "datasetFieldSigma": 0.0, 
      "datasetFieldNullCount": 0.0, 
      "datasetFieldObsCount": 0.0, 
      "datasetFieldKurtosis": 0.0, 
      "datasetFieldSkewness": 0.0, 
      "frequencyDistribution": null, 
      "id": null, 
      "fieldType": "STRING" 
     } 
    }] 
} 
+0

您是如何輕鬆清理JSON的?如果我只是刪除所有/它說它不合適的JSON? – theMadKing

+0

老實說,我只是打開它在的IntelliJ臨時文件,並通過它讀取。我全部換成了'\「'和'」'然後清理了手。我不知道,我花了很多時間與JSON我猜:-) – eric

+0

謝謝哈,我做了一個簡單的替換所有\它嚇壞了,我會看看它的感謝。 – theMadKing

1

是的,你的記錄描述爲字符串不是文檔。刪除報價和\並再次發送。

{ 
    "Dataset": "kh_offers", 
    "Instance": "20140817", 
    "Record": [{ 

     "30": {"errorCode":null,"runStatusId":null,"lakeHdfsPath":"/user/jmblnvr/20140817_011500_zoot_kohls_offer_init.dat","fieldIndex":30,"datasetFieldName":"FIRST_PYMT_DATE","datasetFieldSum":0.0,"datasetFieldMin":0.0,"datasetFieldMax":0.0,"datasetFieldMean":0.0,"datasetFieldSigma":0.0,"datasetFieldNullCount":0.0,"datasetFieldObsCount":0.0,"datasetFieldKurtosis":0.0,"datasetFieldSkewness":0.0,"frequencyDistribution":null,"id":null,"fieldType":"STRING"} 
    }] 
} 

這樣