0

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"}}}}}
Harry
  • 3,072
  • 6
  • 43
  • 100

1 Answers1

1

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.

Kamal Kunjapur
  • 8,547
  • 2
  • 22
  • 32
  • Yes but elastic search internally stores as mapping -> mapping -> properties, check this link : so I use the request.source with {"mappings":{"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}} and it worked – Harry Jun 22 '20 at 12:42
  • for reference check this link : https://techoverflow.net/2019/04/17/how-to-fix-elasticsearch-root-mapping-definition-has-unsupported-parameters/ – Harry Jun 22 '20 at 12:43
  • Apologies, I made use of method `request.mapping(jsonString,XContentType.JSON);` and not the one you've used i.e. `request.source(jsonString, XContenType.JSON);`. I believe both should be correct enough and would eventually convert into correct JSON format required by elasticsearch. If you read the source code for `CreateRequestIndex` you would be able to see how both the methods are being used. – Kamal Kunjapur Jun 22 '20 at 14:04
  • Strange I've tried using source method with the mapping string you have and I still get the issue. Could you update the maven details, just want to check what ES version are you making use of. I've tried with 7.7 and both the times, only the JSON I've mentioned in the answer works, but not what you've mentioned in comment. – Kamal Kunjapur Jun 22 '20 at 14:13
  • Could you help me on this please : https://stackoverflow.com/questions/62671455/elasticsearch-put-role-api – Harry Jul 02 '20 at 09:04
  • @Harry sure please give me sometime. I will update my findings as soon as I can. – Kamal Kunjapur Jul 02 '20 at 14:37