Install of apt package is failing

OK, I found what the problem is. I extracted the .deb and in DEBIAN/preinst, if it doesn't find java, it just exits with an error code of 1 (the 'echo' statements are never displayed, the install just fails).

I added 'default-jre' to the Depends line of DEBIAN/control:

Depends: bash, libc6, adduser, coreutils, default-jre

Then rebuilt the .deb. It installs successfully if the default-jre package is already installed and installs it as a dependency if it's not:

apt-get install ./elasticsearch-6.4.1-mine.deb

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'elasticsearch' instead of './elasticsearch-6.4.1-mine.deb'
The following additional packages will be installed:
default-jre
Suggested packages:
default-java-plugin
The following NEW packages will be installed:
default-jre elasticsearch
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,092 B/82.4 MB of archives.
After this operation, 151 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 default-jre amd64 2:1.10-63ubuntu1~02 [1,092 B]
Get:2 /tmp/elasticsearch-6.4.1-mine.deb elasticsearch all 6.4.1 [82.4 MB]
Fetched 1,092 B in 1s (867 B/s)
Selecting previously unselected package default-jre.
(Reading database ... 116894 files and directories currently installed.)
Preparing to unpack .../default-jre_2%3a1.10-63ubuntu1~02_amd64.deb ...
Unpacking default-jre (2:1.10-63ubuntu1~02) ...
Selecting previously unselected package elasticsearch.
Preparing to unpack /tmp/elasticsearch-6.4.1-mine.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (6.4.1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up default-jre (2:1.10-63ubuntu1~02) ...
Setting up elasticsearch (6.4.1) ...
Created elasticsearch keystore in /etc/elasticsearch
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for ureadahead (0.100.0-20) ...

I know you probably don't want to necessarily lock users into using the default-jre package but if they're going through the trouble of installing the elasticsearch package from the repo, that's probably what they'll want to install anyway.

Cheers