HighLevelRestClient appears inconsistent between hosted elasticsearch and testcontainers-java-module-elasticsearch


(Tristan Buckner) #1

I have a weird issue that might be a problem with testcontainers-java-module-elasticsearch or possibly with the HighLevelRestClient.

I wrote a test that connected directly to our hosted cloud.elastic.co cluster and created some indices with a mapping and then deleted some based on some criteria. It worked fine, but obviously I didn't want to actually have the test depend on the real cluster so I looked around and found the testcontainers-java-module-elasticsearch package.

So I changed the test to use a client pointed at the container and now I get this when executing a create index request (with a mapping):
ElasticsearchStatusException[Elasticsearch exception [type=exception, reason=Incorrect HTTP method for uri [//schedule_index_2012-04-24/?master_timeout=30s&timeout=30s] and method [PUT], allowed: [POST]]
]
Does this mean that the High Level Client uses the wrong HTTP method but that the host 6.2.2 service doesn't care, or is there something inconsistent between the 6.2.2 on the hosted cluster and the 6.2.2 in the docker image?

Here is the code that creates the index with the High Level Client:

protected void createScheduleIndex(String prefix, LocalDate indexDay) throws IOException {
        String indexName = String.format("%s_%s", prefix, indexDay);
        try {
            CreateIndexRequest create = new CreateIndexRequest("/" + indexName)
                    .mapping(Indexer.SCHEDULE_TYPE, mapping);
            CreateIndexResponse createIndexResponse = this.esClient.indices().create(create);
            logger.info("Create index response: {}", objectMapper.writeValueAsString(createIndexResponse));
        } catch (ElasticsearchStatusException e) {
            if (e.getDetailedMessage().contains("type=resource_already_exists_exception")) {
                logger.info("Index {} already exists. No mapping changes will occur.", indexName);
            } else {
                throw e;
            }
        }
    }

Looking at the source of the High Level Client, org.elasticsearch.client.Request#createIndex definitely uses PUT rather than POST. Anyone know why it would work against the hosted cluster, but not the docker container provided by testcontainers-java-module-elasticsearch?


(Thiago Souza) #2

Try removing the extra / from the index name in the CreateIndexRequest constructor


(Tristan Buckner) #3

That worked, thanks. Does the hosted service sit behind something that happened to strip it?


(Thiago Souza) #4

Not really. It is not expected to use a / there. If you check the error message, the path is starting with double slashes // which should be wrong to any cluster (either on-prem or cloud)


(system) #5

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