3

I am using java high level rest client for integrating elasticsearch in my application,But not able to create an index

somewhere I found that to execute the request we need to use index(request) method (which I have commented in my code) but it is shwing that index(request) method is deprecated from the type RestHighLevelClient.

Here is my code:

@GetMapping("/createIndex")
public boolean createIndex() throws IOException {


    IndexRequest request = new IndexRequest(
            "muviuser", 
            "user",  
            "1");   
    String jsonString = "{" +
            "\"user\":\"Bran\"," +
            "\"postDate\":\"2018-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
            "}";
    request.source(jsonString, XContentType.JSON);

    //client.index(request);
}

1 Answer 1

3

As the documentation explains, here's how to create an index using the high-level ES API:

    CreateIndexRequest request = new CreateIndexRequest(indexName);
    request.mapping("_doc", mappingJson, XContentType.JSON);
    CreateIndexResponse response = client.indices().create(request);

Note that your source document looks wrong, as it needs to follow the specific ES request format with mappings, settings and aliases. Better to specify just the mapping instead.

Sign up to request clarification or add additional context in comments.

2 Comments

That no longer seems to be accurate, a CreateIndexRequest no longer accepts a document type argument.
My post applies to ES 6.0. However, it still worked when I tried with ES 7.1.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.