0

I am using IndexRequest from elastic 6.3.2. Now I changed to version 7.6.2. How can I do the same below steps using the CreateIndexRequest?

Elastic rest high level client 6.3.2 code:

 public Object createIndex(Object document, String id) throws IOException {

        Map documentMapper = objectMapper.convertValue(document, Map.class);

        IndexRequest indexRequest = new IndexRequest(this.getIndexName(),
                type, id).source(documentMapper, XContentType.JSON);

        IndexResponse indexResponse = client.index(indexRequest);
        return null;
    }

After switching to 7.6.2 I am not able to create type, id and source in CreateIndexRequest.

Nikolay Vasiliev
  • 5,656
  • 22
  • 31
Tirumalesh
  • 95
  • 1
  • 17

1 Answers1

2

types are deprecated in Elasticsearch 7.X and below is the code, which works for me using the resthighlevel client.

Please note I am not using the type and id in CreateIndexRequest method of resthighlevel client.

String indexString = jsonUtil.getStringFromFile(indexName + ".mapping");
CreateIndexRequest request = new CreateIndexRequest(indexName);
request.source(indexString, XContentType.JSON);
client.indices().create(request, RequestOptions.DEFAULT);

Please see removal of types for more information.

Amit
  • 30,756
  • 6
  • 57
  • 88