Search code examples
javaelasticsearchelasticsearch-7resthighlevelclient

Create Index Request Mapping is failing in elastic search


I am trying to create the Join data type in the elastic search index, It is working from the kibana console / via rest but when I try to create the mapping for the index programmatically it fails with the below error,

java.util.concurrent.ExecutionException: RemoteTransportException[[3cfb4e163654][172.17.0.2:9300][indices:admin/create]]; nested: MapperParsingException[Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:  [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]]; nested: MapperParsingException[Root mapping definition has unsupported parameters:  [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]];

Mapping :

{
    "properties": {
      "my_id": {
        "type": "keyword"
      },
      "my_join_field": { 
        "type": "join",
        "relations": {
          "question": "answer" 
        }
      }
    }
  }

Code :

public void createIndex(ReIndex indexObject) throws XXXDefinedException {
        String index = indexObject.getDestinationIndex();
        try {
            LOG.info("Initiating the index creation process for the " + index);
            CreateIndexRequest request = new CreateIndexRequest(index);
            if (!CommonUtils.isEmptyMap(indexObject.getMapping())) {
                LOG.info("Index Mapping Available : " + index);
                String indexMapping = new GsonBuilder().create().toJson(indexObject.getMapping());
                request.source(indexMapping, XContentType.JSON);
            }
            AcknowledgedResponse indexResponse = client.admin().indices().create(request).get();
            client.admin().indices().prepareRefresh().execute().actionGet();
            LOG.info("Index is created successfully : " + indexResponse);
        } catch (Exception e) {
            throw new XXXDefinedException (e);
        }
    }

where the inputObject.getMapping() has the following mapping :

  {"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}

Solution

  • Your inputObject.getMapping() should not be having the mapping part. Could you make the change in inputObject.getMapping() you have from:

    {"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}
    

    to

    {"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}
    

    Let me know if that works out.