好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

javaapi中嵌套性实体存储到es报错:IllegalArgumentException

Elasticsearch | 作者 PhoebM | 发布于2018年03月05日 | 阅读数:8138

测试代码,转出map<string ,object>里面的子实体没有值
 @Test
public void addTestJson() {
ElasticClientOrIndex elasticClientOrIndex = new ElasticClientOrIndexImp();
TransportClient client = elasticClientOrIndex.getClient();
itooDataEntity = returnEntity();
String json = JSON.toJSON(itooDataEntity).toString();
IndexResponse response = client.prepareIndex("itoo-user-whole", "ItooWebContentList",
itooDataEntity.getUserId()).setSource(json).execute().actionGet();
}

 
java.lang.IllegalArgumentException: The number of object passed must be even but was [1]

at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:360)
at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:347)
at org.elasticsearch.action.index.IndexRequestBuilder.setSource(IndexRequestBuilder.java:161)
at testTransDataToEs.addTestJson(testTransDataToEs.java:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
已邀请:

陈将军

赞同来自: zwy_

新版的API中使用setSource时,参数的个数必须是偶数,否则需要加上
setSource(json, XContentType.JSON)

要回复问题请先登录注册