Index not properly setup on Play distribution - Parent field can't be specified

Hey guys,

I do have an issue with Elasticsearch and in particular with the Java API of Elasticsearch.

I've a Play application which runs an Elasticsearch instance, which is created by the help of the respective Java API. Upon startup of the application, an Elasticsearch index is created. This index will be used for data handling during the runtime. When I run the application locally on my Mac (it does work on Windows too), everything is running smoothly. However, as soon as I deploy the application on a virtual machine (right now a Ubuntu, though I tried it with a Windows one as well), I face some weird issue. The application starts, sets up up my Elasticsearch server and creates the index (not properly). Now, if I want to create a new document, I receive the following error:

java.lang.IllegalArgumentException: Can't specify parent if no parent field has been configured
    at org.elasticsearch.action.index.IndexRequest.process(IndexRequest.java:617)
    at org.elasticsearch.action.index.TransportIndexAction.resolveRequest(TransportIndexAction.java:131)
  at ....

In order to give you a better idea about the structure of the index I attach the relevant code snippet but also want to explain quickly the setup.

My top entity is some kind of document. The mapping is pretty simple, it has several fields. The next entity is a "ArticleContainer". Besides some unrelevant fields, it has one field called "Law". This field contains the id of its document. Moreover, I have "Articles". Among other fields, an Article has a emphasized text"_parent" field of type "ArticleContainer" and thus is a child of an "ArticleContainer". The last entity is an "Annotation". This one is again a child of an "Article" and thus has a field "_parent" of type "Article".

Here is the code which creates the index:

private static void createIndex() {
    client.admin().indices().prepareCreate(indexName).execute().actionGet();

    String mappingArticle = null;
    String mappingAnnotation = null;
    String mappingArticleContainer = null;
    try {
        mappingArticle = XContentFactory.jsonBuilder().startObject().startObject(Article.SC_TYPE).startObject("_parent").field("type", ArticleContainer.SC_TYPE).endObject().startObject("_routing").field("required", true).endObject().startObject("properties").startObject("ArticleContent").field("type", "string").endObject().endObject().endObject().endObject().string();
        mappingAnnotation = XContentFactory.jsonBuilder().startObject().startObject(Annotation.SC_TYPE).startObject("_parent").field("type", Article.SC_TYPE).endObject().startObject("_routing").field("required", true).endObject().startObject("properties").startObject("feature").field("type", "nested").endObject().startObject("AnnotationType").field("type", "string").field("index", "not_analyzed").endObject().startObject("Content").field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject().string();
        mappingArticleContainer = XContentFactory.jsonBuilder().startObject().startObject(ArticleContainer.SC_TYPE).startObject("properties").startObject("ParentArticleContainer").field("type", "string").field("index", "not_analyzed").endObject().startObject(Law.SC_TYPE).field("type", "string").field("index", "not_analyzed").endObject().startObject(DraftedDocument.SC_TYPE).field("type", "string").field("index", "not_analyzed").endObject().startObject(Patent.SC_TYPE).field("type", "string").field("index", "not_analyzed").endObject().endObject().endObject().endObject().string();
    } catch (IOException e) {
        e.printStackTrace();
    }
    client.admin().indices().preparePutMapping(indexName).setType(Annotation.SC_TYPE).setSource(mappingAnnotation).execute().actionGet();
    client.admin().indices().preparePutMapping(indexName).setType(Article.SC_TYPE).setSource(mappingArticle).execute().actionGet();
    client.admin().indices().preparePutMapping(indexName).setType(ArticleContainer.SC_TYPE).setSource(mappingArticleContainer).execute().actionGet();
}

The weird part is, as already mentioned, that it is working locally when I just run the Play application. For the production version on the VM, I build the distribution with

play dist

and start it with

/var/lib/jenkins/jobs/MyApp/bin/myApp -Dhttp.port=3000 -Dhttp.address=0.0.0.0 -Dpidfile.path=/var/lib/jenkins/jobs/MyApp/myApp.pid -Dplay.crypto.secret=mysecret

I'd appreciate any help or hints!

Hey,

how did you ensure, that you actually put the mapping correctly and that it has been applied, before indexing data?

--Alex