generator-jhipster: App with Elasticsearch doesn't work out-of-the-box with Heroku

Overview of the issue

I’m updating 21-Points Health as part of the JHipster Mini-Book. When I deploy to Heroku, it fails to configure the Elasticsearch add-on. I experienced a similar issue when I updated the book for JHipster v5.

When I run jhipster heroku, it does mention something about Elasticsearch in that “no new Elasticsearch addon created”.

Provisioning addons

Provisioning database addon heroku-postgresql --as DATABASE

No suitable cache addon for cacheprovider ehcache available.

Creating Heroku deployment files
    force .yo-rc-global.json
   create Procfile
    force .yo-rc.json
   create system.properties
   create gradle/heroku.gradle
 conflict build.gradle
? Overwrite build.gradle? (ynarxdeiH) No new Elasticsearch addon created
? Overwrite build.gradle? overwrite this and all others

When I tail the logs after startup, it basically says the Bonsai Elasticsearch add-on wasn’t configured.

2022-05-13T15:31:15.077985+00:00 app[web.1]: Caused by: java.net.UnknownHostException: 
  ${BONSAI_URL}: Name or service not known

I tried installing the add-on manually:

$ heroku addons:create bonsai:sandbox-6
Creating bonsai:sandbox-6 on ⬢ health-by-points... free
Your Bonsai cluster is being provisioned.

Please run `heroku addons:open bonsai` and navigate to the Notifications tab to enter contact information for this resource.

Please contact support@bonsai.io for help.
bonsai-clean-03403 is being created in the background. The app will restart when complete...
Use heroku addons:info bonsai-clean-03403 to check creation progress
Use heroku addons:docs bonsai to view documentation

Then, I ran heroku restart. Now it fails with:

... app[web.1]: Caused by: org.elasticsearch.ElasticsearchException: Invalid or missing build flavor [oss]
... app[web.1]: at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2084)
... app[web.1]: at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1732)
... app[web.1]: at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1717)
... app[web.1]: at org.elasticsearch.client.IndicesClient.exists(IndicesClient.java:963)
... app[web.1]: at org.springframework.data.elasticsearch.core.RestIndexTemplate.lambda$doExists$2(RestIndexTemplate.java:103)
... app[web.1]: at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:408)

If I google the error, I land at https://github.com/elastic/elasticsearch/issues/76091.

Motivation for or Use Case

Elasticsearch + Heroku should work out-of-the-box.

Reproduce the error

Create a new app with Elasticsearch and deploy it to Heroku with jhipster heroku.

Related issues

We experienced a similar issue in June 2018: https://github.com/jhipster/generator-jhipster/issues/7810

Suggest a Fix

Fix the Heroku sub-generator so it works.

JHipster Version(s)
twenty-one-points@0.0.1-SNAPSHOT /Users/mraible/dev/21-points
└── generator-jhipster@7.8.1

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "TwentyOnePoints",
    "blueprints": [],
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1651460089159,
    "cypressCoverage": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entitySuffix": "",
    "herokuAppName": "health-by-pints",
    "herokuDeployType": "git",
    "herokuJavaVersion": "11",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.8.1",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "fr"],
    "messageBroker": false,
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "org.jhipster.health",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": "elasticsearch",
    "serverPort": "8080",
    "serverSideOptions": ["searchEngine:elasticsearch"],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

openjdk version “17.0.3” 2022-04-19 OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06) OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06, mixed mode, sharing)

git version 2.32.0 (Apple Git-132)

node: v16.15.0

npm: 8.6.0

Docker version 20.10.14, build a224086

Docker Compose version v2.5.0

Browsers and Operating System

Chrome and macOS Monterey

  • Checking this box is mandatory (this is just to show you read everything)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 32 (26 by maintainers)

Commits related to this issue

Most upvoted comments

Hey folks, founder of Bonsai here. I can confirm that the Heroku Bonsai add-on supports the last open source licensed (Apache 2) version of Elasticsearch, which is 7.10. Newer versions are under Elastic’s proprietary license, which Bonsai does have an agreement with Elastic to support, but I don’t have an ETA of when that will be available within our Heroku add-on.

@nz Hi Nick. Do you have plans to support the latest version of Elasticsearch that Spring Boot 3 ships with?

If not, I think we should drop our auto-provisioning of the Bonsai add-on when deploying to Heroku. Instead, we can show users how to deploy ES in a Docker container on Heroku, or how to configure their app to use Elastic’s cloud and their 14-day free trial.

Elastic never had a free tier (on Heroku or elsewhere). Outside of Heroku we have free trials, but I’m afraid we’re a bit out of options here. Pinning the dependency if run on Heroku as described in https://github.com/jhipster/generator-jhipster/issues/18650#issuecomment-1127734691 sounds like the best option for now.

PS: Since “proprietary” tends to be misunderstood since it has various shapes — the only limitation of Elasticsearch now is that you cannot provide it as a service; still free to use like before, source code is where it always was,…

Hi @nz thanks for your input. Sounds like a valid alternative we can consider. Right now I think it’s out of scope as we rely on spring data’s integration of elastic search (not sure if openssearch is supported).

@DanielFran This is a bug rather than an enhancement, IMO. It worked the last time I tried it, albeit in 2018.