The number of object passed must be even but was [1]
1.失败,使用TransportClient
public static void bulkInsert(TransportClient client) throws IOException {
List<Person> ps=new ArrayList<Person>();
Person one=new Person();
one.setId("1");
one.setAddress("add");
one.setMobile("1111");
one.setSex("f");
one.setUsername("www");
ps.add(one); Person two=new Person();
two.setId("2");
two.setAddress("add");
two.setMobile("2222");
two.setSex("f");
two.setUsername("www");
ps.add(two); Persons pss=new Persons();
pss.setPersons(ps);
pss.setUuid("uiid"); String jsonStr=JSON.toJSONString(pss);
System.out.println(jsonStr); IndexResponse response = client.prepareIndex("www", "www").setSource(jsonStr).get();
System.out.println("创建成功!"); }
原因是:setSource方法不支持json,源码如下:
/**
* Constructs a simple document with a field name and value pairs.
* <p>
* <b>Note: the number of objects passed to this method must be an even
* number. Also the first argument in each pair (the field name) must have a
* valid String representation.</b>
* </p>
*/
public IndexRequestBuilder setSource(Object... source) {
request.source(source);
return this;
}
2.成功,使用RestHighLevelClient 可以直接使用json
public static void InsertByJson(RestHighLevelClient client) throws IOException {
List<Person> ps=new ArrayList<Person>();
Person one=new Person();
one.setId("1");
one.setAddress("add");
one.setMobile("1111");
one.setSex("f");
one.setUsername("www");
ps.add(one); Person two=new Person();
two.setId("2");
two.setAddress("add");
two.setMobile("2222");
two.setSex("f");
two.setUsername("www");
ps.add(two); Persons pss=new Persons();
pss.setPersons(ps);
pss.setUuid("uiid"); String jsonStr=JSON.toJSONString(pss);
System.out.println(jsonStr);
IndexRequest req = new IndexRequest("www", "www");
req.source(jsonStr, XContentType.JSON);
IndexResponse response = client.index(req);
System.out.println("创建成功!"); }
The number of object passed must be even but was [1]的更多相关文章
- ES添加文档 踩坑之 —— The number of object passed must be even but was [1]
读取文件,获取json格式的数据doc, 然后使用 bulkRequestBuilder.add(client.prepareIndex(index, type, id).setSource(doc) ...
- ElasticSearch-The number of object passed must be even but was [1]-问题解决
ES版本:6.4.3 1.The number of object passed must be even but was [1] 问题代码: IndexRequest indexRequest = ...
- Javascript中类型: undefined, number ,string ,object ,boolean
var a1; var a2 = true;var a3 = 1;var a4 = "Hello";var a5 = new Object();var a6 = null;var ...
- [bug] Unrecognized token 'code': was expecting (JSON String, Number, Array, Object,'true', 'false' or 'null')
JSON格式有误,需用JSON.stringify()函数转换一下 参考 https://www.cnblogs.com/sunyanblog/p/13788740.html https://www. ...
- elasticsearch-java异常
1. Unsupported major.minor version 52.0 java的jdk版本过低导致,需要更换为jdk1.8+ 2. elasticsearch 的version在pom中提示 ...
- elasticsearch 导入基础数据并索引之 geo_point
elasticsearch 中的地理信息存储, 有geo_point形式和geo_shape两种形式 此篇只叙述geo_point, 地理位置需要声明为特殊的类型, 不显示在mapping中定义的话, ...
- SAP NUMBER RANGE维护配置object FBN1 Deletion only possible if status is initial
背景: 错误日志: SAP FBN1 Deletion only possible if status is initial 场景: 如果目标机已有NUMBER RANGE 不为0,需要删除配置年为9 ...
- Chapter 3 Discovering Classes and Object
Chatper 3 Discovering Classes and Object Exercises: 1.What is a class? A class is a template for man ...
- Directive Definition Object
不知道为什么这个我并没有想翻译过来的欲望,或许我并没有都看熟透,不好误人子弟,原版奉上. Here's an example directive declared with a Directive D ...
随机推荐
- Oracle定义DES加密解密及MD5加密函数
http://blog.csdn.net/xdweleven/article/details/38319351 (1)DES加密函数create or replace functionencryp ...
- 让Easy UI 的DataGrid直接内嵌的JSON对象,并重写form load 方法
前言 我有这样的JSON对象 { "UserName": "jf", "UserPwd": "123456", &quo ...
- ASP.NET WEB API 返回JSON 出现2个双引号问题
前言 在使用ASP.NET WEB API时,我想在某个方法返回JSON格式的数据,于是首先想到的就是手动构建JSON字符串,如:"{\"result\" ...
- 实现EventHandler的监测
的监测", "category":"", "tags":"", "publish":&qu ...
- 使用cropper插件进行图片裁剪 并上传
cropper插件的使用和 github地址: github 官方实例 我参考的中文文档: https://www.cnblogs.com/baka-sky/p/8001577.html 因为我是.n ...
- T-SQL分页查询语句
使用 ROW_NUMBER(),SQL Server版本要求2005及以上. SELECT * FROM ( SELECT *,ROW_NUMBER() OVER(ORDER BY UserID) A ...
- sqlServer数据库常用连接字符串
sqlServer 数据库常用连接字符串 用户名和密码验证的方式去连接到数据库服务器 <add name="conStr" connectionString=" ...
- JVM伪共享
CPU缓存中的cache line缓存行是缓存的最小单位,同一个时刻内只允许一个cpu内核进行操作.一般,缓存行的大小为64字节,这样的大小可以存放多个java对象的对象头.因此,当两个不同的线程同时 ...
- 907. Sum of Subarray Minimums
Given an array of integers A, find the sum of min(B), where B ranges over every (contiguous) subarra ...
- 《JAVA与模式》之桥梁模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述桥梁(Bridge)模式的: 桥梁模式是对象的结构模式.又称为柄体(Handle and Body)模式或接口(Interface)模式. ...