First of all, I did tried to upsert to Elastic Search with document. So I used org.elasticsearch.action.update.UpdateRequest object to upsert process.
The code is blow.
String type = map.remove("<%=UPDATE%>")+"";
String index = map.remove("<%=INDEX%>")+"";
String id = map.remove("<%=ID%>")+"";
<%=cid%>_request.add(new org.elasticsearch.action.update.UpdateRequest(index, type, id).doc(map, org.elasticsearch.common.xcontent.XContentType.JSON).docAsUpsert(<%=DOC_AS_UPSERT%>));
The problem is that when I had put the document without index mapping, it was so successfully working but what if index mapping was exist before or created, it put out message as blow
ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Rejecting mapping update to [test-es1] as the final mapping would have more than 1 type: [_doc, UPDATE]]]
and failed to upsert.
When I had been removing second parameter of UpdateRequest object, everything was so good working. Successful code is down below.
String type = map.remove("<%=TYPE%>")+"";
String index = map.remove("<%=INDEX%>")+"";
String id = map.remove("<%=ID%>")+"";
<%=cid%>_request.add(new org.elasticsearch.action.update.UpdateRequest(index, id).doc(map, org.elasticsearch.common.xcontent.XContentType.JSON).docAsUpsert(<%=DOC_AS_UPSERT%>));
what I mean is when I created 'UpdateRequest' object to upsert with type as seconds parameter of constructor, Elastic Search server responded reject message out.
But after I removed type parameter on UpdateRequest object, everything is OK. see below.
new UpdateRequest(index, type, id) -----------> It's out reject message.
new UpdateRequest(index, id) ------------> It's OK.
Elastic Search's reject message is below.
ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Rejecting mapping update to [test-es1] as the final mapping would have more than 1 type: [_doc, UPDATE]]]
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.