Create Index Request Mapping is failing in elastic search

百般思念 提交于 2020-06-27 06:11:10

问题


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:


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.



来源:https://stackoverflow.com/questions/62463191/create-index-request-mapping-is-failing-in-elastic-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!