joerghoh commented on code in PR #709: URL: https://github.com/apache/jackrabbit-oak/pull/709#discussion_r978383530
########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java: ########## @@ -41,51 +48,65 @@ class ElasticIndexHelper { // Unset the refresh interval and disable replicas at index creation to optimize for initial loads // https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html - private static final String INITIAL_REFRESH_INTERVAL = "-1"; - private static final int INITIAL_NUMBER_OF_REPLICAS = 0; + private static final Time INITIAL_REFRESH_INTERVAL = Time.of(b -> b.time("-1")); + private static final String INITIAL_NUMBER_OF_REPLICAS = "0"; /** * Returns a {@code CreateIndexRequest} with settings and mappings translated from the specified {@code ElasticIndexDefinition}. * The returned object can be used to create and index optimized for bulk loads (eg: reindexing) but not for queries. * To make it usable, a #enableIndexRequest needs to be performed. + * * @param remoteIndexName the final index name * @param indexDefinition the definition used to read settings/mappings * @return a {@code CreateIndexRequest} - * @throws IOException if an error happens while creating the request - * - * TODO: index create cannot be migrated to the ES Java client: it does not support custom mappings/settings needed to configure elastiknn. - * See discussion in https://discuss.elastic.co/t/elasticsearch-java-client-support-for-custom-mappings-settings/303172 - * The migration will continue when this roadmap item gets fixed https://github.com/elastic/elasticsearch-java/issues/252 */ - public static CreateIndexRequest createIndexRequest(String remoteIndexName, ElasticIndexDefinition indexDefinition) throws IOException { - final CreateIndexRequest request = new CreateIndexRequest(remoteIndexName); - - // provision settings - request.settings(loadSettings(indexDefinition)); + public static CreateIndexRequest createIndexRequest(@NotNull String remoteIndexName, + @NotNull ElasticIndexDefinition indexDefinition) { + return new CreateIndexRequest.Builder() + .index(remoteIndexName) + .settings(s -> loadSettings(s, indexDefinition)) + .mappings(s -> loadMappings(s, indexDefinition)) + .build(); + } - // provision mappings - final XContentBuilder mappingBuilder = XContentFactory.jsonBuilder(); - mappingBuilder.startObject(); - { - mappingBuilder.startObject("properties"); - { - mapInternalProperties(mappingBuilder); - mapIndexRules(indexDefinition, mappingBuilder); - } - mappingBuilder.endObject(); - } - mappingBuilder.endObject(); - request.mapping(mappingBuilder); + private static ObjectBuilder<TypeMapping> loadMappings(@NotNull TypeMapping.Builder builder, + @NotNull ElasticIndexDefinition indexDefinition) { + mapInternalProperties(builder); + mapIndexRules(builder, indexDefinition); + return builder; + } - return request; + private static void mapInternalProperties(@NotNull TypeMapping.Builder builder) { + builder.properties(FieldNames.PATH, + b1 -> b1.keyword(builder3 -> builder3)) + .properties(FieldNames.ANCESTORS, + b1 -> b1.text( + b2 -> b2.analyzer("ancestor_analyzer") + .searchAnalyzer("keyword") + .searchQuoteAnalyzer("keyword"))) + .properties(FieldNames.PATH_DEPTH, + b1 -> b1.integer( + b2 -> b2.docValues(false))) + .properties(FieldNames.FULLTEXT, + b1 -> b1.text( + b2 -> b2.analyzer("oak_analyzer"))); + // TODO: the mapping below is for features currently not supported. These need to be reviewed Review Comment: would it make sense to create an OAK ticket for it? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org