今天在获取插入索引数据的时候,一直提示插入不成功,尝试了很多方法,原来是因为在插入的时候应该先 插入Latitude后插入longitude修改后的代码如下
public boolean insertIndexDoc(String indexname, String type,
List<Require> list) throws ApplicationException, Exception {
// TODO Auto-generated method stub
String location=null;
JestClient jestHttpClient = Connection.getClient();
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(indexname)
.defaultType(type);
for(Require req:list){
String json = "{"+""location":"+"""+req.getLatitude()+","+req.getLongitude()+"""+","
+""id":"+"""+req.getId()+"""+","+""user_id":"+"""+req.getUser_id()+"""+","
+""need_code":"+"""+req.getNeed_code()+"""+","+""craete_date":"+"""+req.getCreate_date()+"""+","
+""text":"+"""+req.getText()+"""+","+"}";
// System.out.println(json);
Index index = new Index.Builder(json).build();
bulk.addAction(index);
}
BulkResult br = jestHttpClient.execute(bulk.build());
// jestHttpClient.shutdownClient();
return br.isSucceeded();
}