ElasticSearch Java API Client - Create index with type mapping

I am migrating some code which uses the old rest high level client to the Java API Client (Starting at 7.17.22 with plans to migrate to 8.X immediately after), and am trying to recreate the mapping for a CreateIndexRequest that was originally built with the now removed XContentBuilder class

My old code:

XContentBuilder mapping = null;
            mapping = jsonBuilder()
                    .startObject()
                        .startObject("settings").value(esIndexSettings).endObject()
                        .startObject("mappings")
                            .startObject(DEFAULT_TYPE).field("date_detection", false)
                                .startObject("properties")
                                    .startObject("action").field("type", "text").endObject()
                                    .startObject("deltas")
                                        .startObject("properties")
                                            .startObject("current").field("type", "text").endObject()
                                            .startObject("previous").field("type", "text").endObject()
                                            .startObject("propertyName").field("type", "text").endObject()
                                        .endObject()
                                    .endObject()
                                    .startObject("entityId").field("type", "long").endObject()
                                    .startObject("entityType").field("type", "text").endObject()
                                    .startObject("parentId").field("type", "long").endObject()
                                    .startObject("parentLevel").field("type", "text").endObject()
                                    .startObject("timestamp").field("type", "date").endObject()
                                    .startObject("type").field("type", "text").endObject()
                                    .startObject("userId").field("type", "long").endObject()
                                    .startObject("userName").field("type", "text").endObject()
                                    .startObject("userLogin").field("type", "text").endObject()
                                .endObject()
                            .endObject()
                        .endObject()
                    .endObject();

My current attempt:

CreateIndexRequest request = new CreateIndexRequest.Builder()
                        .index(indexName)
                        .mappings(new TypeMapping.Builder()
                                .dateDetection(false)
                                .properties(Map.of(
                                        // I get stuck here. Not sure how to properly configure fields
                                        "action", new Property.Builder()
                                                .text(new TextProperty.Builder().build())
                                                .build(),
                                        "deltas", new AggregateMetricDoubleProperty.Builder().build()._toProperty()
                                ))
                                .build())
                        .settings(new IndexSettings.Builder()
                                .build())
                        .build();

Welcome!

Have a look at this blog post which describes a bit how to use the new client and some tips on migrating from the old one.

Also this repository contains lot of tests demoing the Java client in action.

For example: