# Elasticsearch integration with CI 2.0

**URL:** <https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922>\
**Category:** Build Environment\
**Tags:** elasticsearch\
**Created:** [June 18, 2019, 8:51am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922 "2019-06-18T08:51:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gccj](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@gccj](https://discuss.circleci.com/u/gccj)\
**Post date:** [June 18, 2019, 8:51am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/1 "2019-06-18T08:51:54Z")

</div>

Hi  
When I tried to solve the same problem like [Elasticsearch integration with CI 2.0 [Rails project]](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0-rails-project/26048)  
Even I set a value for cluster\_name, still got _Cannot find Elasticsearch launch script from [elasticsearch]_ error.

So I tried build a test environment with script below

```
version: 2
defaults: &defaults
  working_directory: ~/xxx
  docker:
    - image: circleci/ruby:2.6.1-node-browsers
    - image: postgres:9.5
    - image: redis
      environment:
        xxxx
    - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.0
      environment:
        - cluster.name: es-test-cluster
        - xpack.security.enabled: false
        - transport.host: localhost
        - network.host: 127.0.0.1
        - http.port: 9250
        - discovery.type: single-node

jobs:
  build:
    <<: *defaults
    steps:
      - run:
          xxxx

```

and used ssh connection to debugging.  
It looks like there no elasticsearch installation!

```
> circleci@6d07ad02c109:~$ which elasticsearch
> circleci@6d07ad02c109:~$ 
> circleci@xxxxxx:~$ find / -type d -name 'elasticsearch'
> circleci@xxxxxx:~$

```

Anyone else who has had this problem?

---

<div class="post-metadata">

**Author:** ![KyleTryon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyletryon/32/9977_2.png) [@KyleTryon](https://discuss.circleci.com/u/KyleTryon)\
**Post date:** [June 18, 2019, 5:18pm UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/2 "2019-06-18T17:18:07Z")

</div>

Hello @gccj,

Welcome to the forum.

Looking at your config I see you have set up a secondary service container for elasticsearch. Each `- image:` is a separate docker image that is accessible via the network. This would mean you can connect to this elasticsearch container from a client installed in your main image.

The command you are executing: `which elasticsearch` is executing on the `circleci/ruby:2.6.1-node-browsers` docker image which does not have the elasticsearch binary installed.

---

<div class="post-metadata">

**Author:** ![gccj](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@gccj](https://discuss.circleci.com/u/gccj)\
**Post date:** [June 19, 2019, 2:23am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/3 "2019-06-19T02:23:35Z")

</div>

Thanks @KyleTryon  
I’d like to install elasticsearch manually on `circleci/ruby:2.6.1-node-browsers` docker image.

---

<div class="post-metadata">

**Author:** ![KyleTryon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyletryon/32/9977_2.png) [@KyleTryon](https://discuss.circleci.com/u/KyleTryon)\
**Post date:** [June 19, 2019, 1:45pm UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/4 "2019-06-19T13:45:05Z")

</div>

Hello,

You have two options to install any software.

1. You may install manually via the `run` command.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html)

2. You can create a custom docker image using `circleci/ruby:2.6.1-node-browsers` as your base image. From there you can publish your own Docker image on the Dockerhub and use this in your projects.

```auto
FROM circleci/ruby:2.6.1-node-browsers
RUN ...

```

Creating a custom Docker image is usually the best option as there are less potential points of failures. A built image using `circleci/ruby:2.6.1-node-browsers` will benefit from any cached layers from this image on our host and will only need to download any additional layers created from the DockerHub.

One note, I would recommend dropping the patch version in the image. Often patches are required to fix issues that may arrise with the image (such as moving/changing packages). Building off `2.6` will allow you to pull the most recent patch which may help avoid issues.

---

<div class="post-metadata">

**Author:** ![AhsenArif](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@AhsenArif](https://discuss.circleci.com/u/AhsenArif)\
**Post date:** [June 20, 2019, 5:53am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/5 "2019-06-20T05:53:41Z")

</div>

@KyleTryon What happens if someone does not want to install Elasticsearch manually. ?  
The problem with provided Elasticsearch images are that the path to location of elasticsearch is not available.

E.g. using the same config as given in the question

```auto
version: 2
defaults: &defaults
  working_directory: ~/xxx
  docker:
    - image: circleci/ruby:2.6.1-node-browsers
    - image: postgres:9.5
    - image: redis
      environment:
        xxxx
    - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.0
      environment:
        - cluster.name: es-test-cluster
        - xpack.security.enabled: false
        - transport.host: localhost
        - network.host: 127.0.0.1
        - http.port: 9250
        - discovery.type: single-node

```

This Elasticsearch cluster requires giving the args `:command` by setting the ENV variable `TEST_CLUSTER_COMMAND` with the path to the Elasticsearch file. (on local system the path is something like `'/Users/.../.../elasticsearch-6.8.0/bin/elasticsearch'`  
Otherwise it throws the error:

```auto
Errno::ENOENT:
  No such file or directory - Cannot find Elasticsearch launch script from [elasticsearch] -- did you pass a correct path?

```

If we use docker image of Elasticsearch, then can you please tell what can be the expected path of where the ES is installed on the directory structure. ?

---

<div class="post-metadata">

**Author:** ![gccj](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@gccj](https://discuss.circleci.com/u/gccj)\
**Post date:** [June 20, 2019, 8:08am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/6 "2019-06-20T08:08:22Z")

</div>

> [@AhsenArif](#):
>
> What happens if someone does not want to install Elasticsearch manually. ?

Hi @AhsenArif  
You can access Elasticsearch service via network.  
The endpoint of Elasticsearch is `localhost:{port you set}`  
That means you haven’t necessary to boot any Elasticsearch service on primary container.

---

<div class="post-metadata">

**Author:** ![gccj](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@gccj](https://discuss.circleci.com/u/gccj)\
**Post date:** [June 20, 2019, 8:15am UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/7 "2019-06-20T08:15:59Z")

</div>

Hi @KyleTryon  
Thank you for your kindness!  
I was able to do my stuff both the way to use docker image and the way to install es manually.

---

<div class="post-metadata">

**Author:** ![KyleTryon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyletryon/32/9977_2.png) [@KyleTryon](https://discuss.circleci.com/u/KyleTryon)\
**Post date:** [June 20, 2019, 1:10pm UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/8 "2019-06-20T13:10:48Z")

</div>

Glad to help @gccj!

@AhsenArif, @gccj is correct above. Please let us know if we can assist you further.

Happy building!

---

<div class="post-metadata">

**Author:** ![KyleTryon](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyletryon/32/9977_2.png) [@KyleTryon](https://discuss.circleci.com/u/KyleTryon)\
**Post date:** [June 20, 2019, 1:11pm UTC](https://discuss.circleci.com/t/elasticsearch-integration-with-ci-2-0/30922/9 "2019-06-20T13:11:05Z")

</div>


