弹性搜索:无法编写期望值的字段名称

时间:2017-06-09 05:20:21

标签: java json elasticsearch

好的,我在这里尝试实现的是解析json字符串并分离其字段并将它们分配给变量。接下来,我创建一个构建器,将数据发送到弹性索引。但我收到这个错误,这真的让我烦恼。我无法前进。

    for (int i = 0; i < jsonarray.length(); i++) {

        try {
            obj = jsonarray.getJSONObject(i);
            System.out.println(obj.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            type = obj.getString("type");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        System.out.println("Values for select");
        try {
            JSONArray jContent = (JSONArray) obj.get("values");

        for (int iterate = 0; iterate < jContent.length(); iterate++) {
            JSONObject inner = jContent.getJSONObject(iterate);
            String inner_label = (String) inner.get("label");
            String val = (String) inner.get("value");
            boolean sel;
            try {
                sel = (boolean) inner.get("selected");

            } catch (JSONException j) {
                sel = false;
            }

            builder.startObject("Extras").field("inner_lab", inner_label).field("inner_value", val).field("Selected", sel).endObject();

        }

    } catch (JSONException e) {

    }

    try {
        label = obj.getString("label");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    try {
        access = obj.getBoolean("access");
    } catch (JSONException e) {
        access = false;
    }

    try {
        role = obj.getString("role");
    } catch (JSONException e) {
        role = null;
    }

    try {
        subtype = obj.getString("subtype");
    } catch (JSONException e) {

        subtype = null;
    }

    try {
        maxlength = obj.getString("maxlength");
    } catch (JSONException e) {

        maxlength = null;
    }

    try {
        name = obj.getString("name");
    } catch (JSONException e) {

        name = null;
    }

    try {
        description = obj.getString("description");
    } catch (JSONException e) {

        description = null;
    }

    try {
        classname = obj.getString("className");
    } catch (JSONException e) {

        classname = null;
    }

    try {
        placeholder = obj.getString("placeholder");
    } catch (JSONException e) {

        placeholder = null;
    }

    try {
        value = obj.getString("value");
    } catch (JSONException e) {

        value = null;
    }

    try {
        required = obj.getBoolean("required");
    } catch (JSONException e) {

        required = false;
    }
    try {
        toggle = obj.getBoolean("toggle");
    } catch (JSONException e) {
        toggle = false;
    }
    try {
        inline = obj.getBoolean("inline");
    } catch (JSONException e) {
        inline = false;
    }
    try {
        enableother = obj.getBoolean("other");
    } catch (JSONException e) {
        enableother = false;
    }
    try {
        multipleFiles = obj.getBoolean("multiple");
    } catch (JSONException e) {
        multipleFiles = false;
    }
    try {
        style = obj.getString("style");
    } catch (JSONException e) {
        style = null;
    }
    try {
        min = obj.getString("min");
    } catch (JSONException e) {
        min = null;
    }
    try {
        max = obj.getString("max");
    } catch (JSONException e) {
        max = null;
    }
    try {
        step = obj.getString("step");
    } catch (JSONException e) {
        step = null;
    }
    try {
        rows = obj.getString("rows");
    } catch (JSONException e) {
        rows = null;
    }

    // //Indexing Data..
    (HERE) builder.startObject("values").field("access", access).field("role", role).field("subtype", subtype)
            .field("maxlength", maxlength).field("name", name).field("description", description)
            .field("className", classname).field("label", label).field("placeholder", placeholder)
            .field("value", value).field("required", required).field("style", style).field("toggle", toggle)
            .field("inline", inline).field("other", enableother).field("multiple", multipleFiles)
            .field("content", content).field("min", min).field("max", max).field("step", step)
            .field("rows", rows).endObject();
    builder.endObject();
    resp = client.prepareIndex("clien", userName).setSource(builder).execute().actionGet();

}

}

在(HERE)位置erro不断出现......无法写出期望值的字段名称。 还有一种更好的方法来实现我在这里尝试做的事情。谢谢你的帮助。

0 个答案:

没有答案