Morifeoluwa Jebutu
Aug 22, 2018 · 3 min read
courtesy google!

Ever been faced with the error in the image below. An index not found exception Error is definitely one anyone who has worked with elastic search would have had to face one time or the other.

Elastic Search is an awesome database that I have recently found out to be very cool to work with. After my initial attempt to run away, I have eventually decided to embrace its uniqueness and value.

Time and time again, the uniqueness of this DB has proved itself as my primary source of frustration. They include Indexing, Mapping and writing queries. But the good news is, with practice and great people around me (@Terragon Engineers) , I have found ways around this.

Now an elastic search index is created when data is being written into it. But what if my first API call is a GET request?

The Bloody terminal exception log

To follow this solution, the following has to be present:

  • Elastic search (should be well installed and started on your PC)
  • Node JS (fair knowledge)
  • elasticsearch client (this provides methods needed for us to easily solve the problem)

Firstly to solve the error above let us set up an elastic search client

Yipee! successfully created an elastic search client

Running the above should output the following

yipee! An elastic search client created

the code above simply creates a connection to our local elastic search instance. To be sure this is working let us ping the DB itself by adding the code below just beneath our connection code.

Now if the image below does not look the same with yours, you might want to check if you have started your elastic search local instance. Depending on what OS and how it was installed, for linux try the following command and try again:

sudo service elasticsearch start
This simply says “it worked!!!”

Been easy so far right? Now let us search our elastic search database for documents. Quite our goal anyways.

Running the above code brings out the same problem you came here to solve. Dude I hope I’m leaving here with an answer??

Take a chill pill! your blessing is around the corner. here comes the buffet!

What we have simply done above is write a function that checks if an index exists. if the response is true it logs out index already exists else it creates the index. Nice!

Now run the getUsers function again and … say it…please do!!!

Yass! its no more failing

One more thing before you go!

Lets try to create a mapping for it in case we want to write to it after.

And we are up and running. This should return a Successfully Created Index 200 { acknowledged: true }.

With this we can now always check or create indexes and create mappings for our elastic search projects.

link to full repo:

…You welcome!!!

Terragon Engineering

We are the @Terragongroup Engineering team

Morifeoluwa Jebutu

Written by

Software Engineer@Terragon Group

Terragon Engineering

We are the @Terragongroup Engineering team

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade