弹性搜索中的嵌套JSON未被提取

时间:2015-12-09 00:06:03

标签: elasticsearch

我有以下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\"}"
    }]
}

我想知道为什么Elastic Search无法处理这个嵌套结构?是因为奇怪的\使我的作家写作时它成为有效的JSON吗?还有其他原因吗?

弹性搜索正在拾取前3个字段,但是当我深入查看记录时,它只是想到它的一个字符串块。

2 个答案:

答案 0 :(得分: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"}
    }]
}
像这样

答案 1 :(得分: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"
        }
    }]
}