Would like to programmatically create indices with mappings in java: 6.1.3 HighLevelRestClient

In the past (ES 2+) I could assign mappings to index names programmatically. In 6.3.1, there is a CreateIndexRequest/Response pair, but the documentation online says to use it with an API which does not exist. Most ES docs talk about using CURL; that's not an option. Can someone point me to a Gist or documentation that doesn't say "this is a preliminary document"?

Similarly, I need to test if the index already exists to avoid re-creating it.

Many thanks.

This is how I'm doing it:

I'll remove that piece of code as soon as the High Level Rest Client will offer it OOTB (6.2.0):

I applied that code in an Eclipse IDE and get this error message:

The method performRequest(String, String, Map<String,String>, Header...) in the type RestClient is not applicable for the arguments (String, String, Map<Object,Object>, StringEntity)

I switched your emptyCollection to new HashMap<String, String>() and the error went away. Still have to test this now. Thanks!

@dadoonet I guess I need to revisit this: It appears to be the case that I can create the index; index settings were about numshards and numreplicas. What is missing for me at the moment is declaring the mappings on that index. The "putMappings" method is missing from the 6+ series. Thoughts?

Just give the mapping at the same time you are creating the index. https://www.elastic.co/guide/en/elasticsearch/reference/6.1/indices-create-index.html#mappings

It appears that worked. Thanks!

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