【发布时间】:2020-09-01 09:50:13
【问题描述】:
这是我发送列表的代码:
for (int i = 0; i < list.size(); i++) {
request.add(new IndexRequest("myindex", "doc").source(list,XContentType.JSON));
count++;
}
我也尝试以地图的形式转换列表,但它正在创建索引并多次点击,但没有推送任何数据:
for (int i = 0; i < list.size(); i++) {
JSONObject dataAsJson = new JSONObject(list);
HashMap<String, Object> dataAsMap = new HashMap<String, Object>(dataAsJson.toMap());
request.add(new IndexRequest("myindex", "doc").source(dataAsMap,XContentType.JSON));
}
这是我要加载的示例数据:
[{"Name" : "ABC",
"Class" : "six",
"Roll" : "330344953 ",
"Team" : "XYX"
},
{"Name" : "AEBC",
"Class" : "six",
"Roll" : "3344953 ",
"Team" : "XYZ"
}]
【问题讨论】:
-
您能否对您尝试索引的数据或列表的内容进行采样。
-
我已经更新了相关数据
-
这个 ObjectMapper 是 org.elasticsearch.index.mapper 的一个类吗?
-
抱歉没有提及。它是Jackson import com.fasterxml.jackson.databind.ObjectMapper 的一个类;也会更新答案。
-
非常感谢!它解决了我的问题。
标签: java json elasticsearch arraylist hashmap