Cannot call apoc.es.put to elastic search 8.6

I updated to elastic 8.6 from elastic 7.17. I am using neo4j 4.4. Before this I run

CALL apoc.es.put("es-container","might_index","docs", "datatest1", null, {
id: "John Doe"
});

it works fine. Now after upgrading to elastic 8.6, I get the error below:

Failed to invoke procedure apoc.es.put: Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://es-container:9200/might_index/docs/datatest1

How to fix this?

I found out that to send to elastic search 8.6, we need to put header

Accept: "application/vnd.elasticsearch+json;compatible-with=7"
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"

In order to do that, I need to recompile the apoc.es source. It involves two files:

  1. ElasticSearch.java
  2. LoadJson.java

To compile, follow https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-caused-by-java-lang-nosuchmethoderror-org-roaringbitmap-container-org-roaringbitmap-arraycontainer-add-char/47477?u=pinox101

Changes in ElasticSearch.java

   private String contentType(Object payload) {
    	// commented by Azhar 31 March 2023 to support Elastic 8.6.2
        //return "application/json";
    	return "application/vnd.elasticsearch+json;compatible-with=7";
    }

Changes in LoadJson.java

  public static Stream<MapResult> loadJsonStream(@Name("urlOrKeyOrBinary") Object urlOrKeyOrBinary, @Name("headers") Map<String, Object> headers, @Name("payload") String payload, String path, boolean failOnError, String compressionAlgo, List<String> pathOptions) {
        if (urlOrKeyOrBinary instanceof String) {
            headers = null != headers ? headers : new HashMap<>();
            headers.putAll(Util.extractCredentialsIfNeeded((String) urlOrKeyOrBinary, failOnError));
        }
        headers.put("Accept","application/vnd.elasticsearch+json;compatible-with=7");
        // Azhar wants to see if the headers was ok
        //System.out.println("headers: " + headers.toString());

I am sorry that the system does not allow me to upload java or jar files. Thank you