Hello Dear,
I had the following code that worked fine with Elasticsearch v0.90.0. This code created child index for a given parent index. When I upgraded ES to 2.x, I get the error, at runtime (there is no compilation error),
java.lang.IllegalArgumentException: Can't specify parent if no parent field has been configured
The line that creates the hell is indicated with comment. It is related to the call " indexRequestbuilder.setParent(parentId)". Please note that I am using Java API.
I would highly appreciate suggestion from the community, for resolving this issue.
Thanks and Regards,
Amal
------------------------------------------------------- code snippet ---------------------------------------------
public void createChildIndex(final Entity entity, final Tenant tenant) throws SearchEngineException {
try {
Map<String, Object> source = entityIndexDocumentPurveyor.purveyDocument(entity, tenant);
String parentId = String.valueOf(tenant.getId());
String indexName = "entities";
String indexId = String.valueOf(entity.getId());
XContentBuilder builder = XContentFactory.jsonBuilder();
if (source.keySet().size() > 0) {
String indexType = StringUtils.substringAfterLast(entity.getClass().getName(), ".").toLowerCase();
this.logger.debug("Indexing {} with id {}...", indexType, entity.getId());
IndexRequestBuilder indexRequestbuilder = this.client.prepareIndex( indexName, indexType, indexId);
indexRequestbuilder.setSource(builder.map(source));
// setting tenant as parent of product or similar entity - creation of child index for a given parent.
if (tenant != null && !Tenant.class.isAssignableFrom(entity.getClass()) ) {
// This statement causes the hell - java.lang.IllegalArgumentException: Can't specify parent if no parent field has been configured
indexRequestbuilder.setParent(parentId);
}
IndexResponse response = indexRequestbuilder.execute().actionGet();
}
} catch (Exception e) {
throw new SearchEngineException("Failed to index entity", e);
}
}