Indexing a document
In ElasticSearch, there are two vital operations namely, Indexing and Searching.
Indexing means inserting one or more document in an index; this is similar to the insert
command of a relational database.
In Lucene, the core engine of ElasticSearch, inserting or updating a document has the same cost. In Lucene and ElasticSearch, update means replace.
Getting ready
You will need a working ElasticSearch cluster and the mapping that was created in the Putting a mapping in an index recipe in this chapter.
How to do it...
To index a document, several REST entry points can be used:
Method |
URL |
---|---|
POST |
http://<server>/<index_name>/<type> |
PUT/POST |
http://<server>/<index_name>/<type> /<id> |
PUT/POST |
http://<server>/<index_name>/<type> /<id>/_create |
We will perform the following steps:
If we consider the type order mentioned in earlier chapters, the call to index a document will be:
curl -XPOST 'http://localhost:9200/myindex...