Managing documents
The APIs for managing documents (index
, delete
, and update
) are the most important after the search ones. In this recipe, we will see how to use them.
Getting ready
You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that supports Scala programming, such as Eclipse (ScalaIDE) or IntelliJ IDEA, with the Scala plugin should be installed.
The code of this recipe can be found in the chapter_15/elastic4s_sample
file and the referred class is DocumentExample
.
How to do it...
For managing documents, we will perform the following steps:
We'll need to import the required classes to execute all the document CRUD operations:
import com.sksamuel.elastic4s.ElasticDsl._
We create the client and ensure that the index and mapping exists:
object DocumentExample extends App with ElasticSearchClientTrait{ val indexName...