Skip to content
Advertisement

ElasticsearchClient 7.16 mapping source from JSON file

I’m migrating our app to new ElastisearchClient for Java. We have few mapping/setting/properties configurations created in JSON files like here Elastic mapping source 7.15. Is it still possible to map sources as in these examples? Or is it fully migrated to:

builders and functional patterns

Currently, we do it like this (RestHighLevelClient 7.14 Elastic):

    String mapping = "mappings/file.json";
    String source = StringUtils.toString(new ClassPathResource(mapping).getInputStream(); //Converting to acceptable json 
    CreateIndex createIndexRequest = new CreateIndexRequest(name);
    createIndexRequest.source(source, XContentType.JSON);

Advertisement

Answer

It’s possible from 7.17.0 version – Documentation

    CreateIndexRequest req = CreateIndexRequest.of(b -> b
    .index("some-index")
    .withJson(input) //Insert here loaded json mapping
);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement