Creating Elastic Search Mapping in Golang

courtesy google.com

Elasticsearch is a real-time distributed and open source full-text search and analytics engine. It is mostly used in Single Page Application (SPA) projects. Elasticsearch is open source developed in Java and used by many big organizations around the world. It is licensed under the Apache license version 2.0. (courtesy https://www.tutorialspoint.com/elasticsearch)

In this article we are going to see how to create a simple elasticsearch mapping for a particular index.

things needed to use this example:

  • elasticsearch (well installed on the machine)
  • appreciable knowledge of programming language (golang in this case)
  • any IDE
  • iris (A golang web framework)
  • github.com/olivere/elastic (An elasticsearch library for golang)

Now let's dive right in by setting up elasticsearch.

Please note that this article can be implemented in any programming language and elastic search client. this is basically just a demo.

we are going to setup connection to elasticsearch and create a client:

(remember that this is golang and we would be running this from a main function which we have chosen not to reveal for now).

the above code should result in the following output depending on what language you are using to implement.

Now we have successfully set up an elasticsearch client running on localhost:9200

If an elastic search instance is not running on the PC or server, could be the reason you are getting this.

now let us create and elastic search mapping for our index. quite easy!!!

you should see a successfully created index. to make things clearer and the code fully workable let’s add our main function

Now we can run this code end to end and have a fully functioning elasticsearch client in golang.

Simple right?! yeah.

claps please.