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"}}}}}
1
  • Can you add import statements also? looks like problem with the indexObject? Commented Jun 21, 2020 at 10:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

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
for reference check this link : techoverflow.net/2019/04/17/…
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.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.