ethrbunny
ethrbunny

Reputation: 10479

Using JEST to write to Elasticsearch 7.3 - invalid POST method

I've been attempting to write some info to a working elasticsearch 7.3 cluster using the JEST api. Some resources:

Have run into this error message:

Incorrect HTTP method for uri [/my_index] and method [POST], allowed: [GET, DELETE, PUT, HEAD]

Im sending the data as follows:

    // write directly to elastic
    Map<String, Object>infoMap = new LinkedHashMap();
    lagInfoMap.put("type", "consumer");
    lagInfoMap.put("topicval", topic);
    lagInfoMap.put("groupval", group);
    lagInfoMap.put("sumval", sumLag);

    try {
        jestResult = jestClient.execute(new Index.Builder(infoMap).index("my_index").build());
        if(!jestResult.isSucceeded()) {
            LOGGER.error(jestResult.toString());
        }
    } catch(IOException ioe) {
        LOGGER.error("Unable to write to elastic", ioe);
        return false;
    }

Seems like it's wanting a PUT request but it's not clear from the docs (or any examples I can find) how to modify the execute method to do so.

Upvotes: 1

Views: 2874

Answers (1)

Amit
Amit

Reputation: 32386

Some days ago I also had the same problem and finally gave up the idea of using JEST for elasticsearch 7.3, from their Github page, it doesn't look like their latest release which is 6.3.1 https://github.com/searchbox-io/Jest/releases , isn't compitable with elasticsearch 7.X.

Elasticsearch 7.X uses the PUT HTTP method to index a document, while the earlier version used the POST method, hence you get the below exception.

Incorrect HTTP method for uri [/my_index] and method [POST], allowed: [GET, DELETE, PUT, HEAD]

I would suggest, you use elasticsearch official high level java client, instead of JEST, this is being developed activity by the elastic, company behind the elasticsearch.

Upvotes: 5

Related Questions