Indexing and Searching Documents with Elastic - Part 2

Indexing and Searching Document with Elastic

In the previous part we learned some basics about elastic and how to get use of the kopf plugin. With this plugin you can call the rest endpoints just with your browser. You can also use the kopf plugin, or curl to run the following rest request to elastic.


Indexes and Types

A document is written into an index. In the previous part we learned what an index is and how indexes get distributed as shards.

An index has a second dimension called "type". With this type you can split documents logically that belong to the same index.


The url for a docuement is allways according to the following scheme:

Writting documents with curl

If an index does not exist, it will be created automatically when you push the first document. By default an elastic index is schemaless and the datatype of a field is determined automatically. This makes it simple to just push a JSON document to the api:


In the request an id of the document is completly missing. This id is generated automatically on the fly by elastic. The response is showing if the document has been index succesfull or not.


With a GET request you can retrieve the document, that we pushed in the previous step:


Now we create an additional document to be able to play a little bit with the elastic query syntax:


By now we've indexed two document into elastic. The first document has the name "hello world" the second one has the name "hello planet".


Writting a simple Search Query for Elastic

Spätestens bei solchen Queries ist das Handling mit Curl unpraktisch ;) und ein Curl Plugin oder Kopf leisten gute Dienste.


With nested queries like this, the handling with curl is getting complucated and a curl browser plugin or the elastic kopf plugin is very helpful.


In the response we can see both documents: