Generating Elastic index templates from Java business model?

Dear Elastic Community,

I've been looking for some way of generating Elasticsearch index templates from Java code, and couldn't really find any out-of the-box solution for it.
Do you know of any existing solution that allows it?

For relational databases this can be done with JPA frameworks like hibernate/eclipseLink that allow you to generate SQL schema from JPA-annotated Java classes.

For Elastic I haven't found anything like that yet - the closest I could find was spring-data-elasticsearch which has some annotations that describe how fields should be mapped when reading/writing.
But I couldn't find any way to generate index templates from Java code.

It seems doable, and it might be a useful feature - it would make it easier to keep the business model in Java clients in sync with Elastic templates and indices, especially in projects where the business model changes dynamically.

To better demonstrate what I have in mind I'm pasting some code below that demonstrates a hypothetical set of annotations that could make it possible to use the Java model not only for writing/reading Elastic documents but also for generation of index templates.

Kind regards,
Tom

@Template(
 name = "vehicle_car_template",
 indexPatterns = { "vehicle_car_*" },
 order=10,
 settings =
    "\"index\" : {"+
    " \"analysis\" : {"+
    "   \"analyzer\" : {"+
    "     \"normalize_alphanum_analyzer\" : {"+
    ...
    "     }"+
    "   }"+
    " }"+
    "}"
)
public interface Car extends Vehicle {

    @Field(
     type = FieldType.KEYWORD,
     copyTo = { "search" },
     analyzer="normalize_alphanum_analyzer"
    )
    String licensePlate();

}


@Template(
 name = "vehicle_template",
 indexPatterns = { "vehicle_*" },
 order = 9
)
public interface Vehicle {

    @Field(
     type = FieldType.INTEGER
    )
    int maxSpeedMph();

}

We don't have that.

Hibernate search supports this if I'm not mistaken.

I wrote this project to automatically create an index with its mapping but you still have to generate the mapping yourself.

When I started with Elasticsearch years ago, some of us had the same idea of creating those annotations but it never became a thing:

Reason is that's too much effort to make it work and maintain for a little value IMHO.

My 2 cents.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.