Managing documents
The APIs for managing documents (such as index
, delete
, and update
) are the most important after the search ones. In this recipe, we will look at how to use them.
Getting ready
You need an up-and-running Elasticsearch installation, as described in the Downloading and installing Elasticsearch recipe of Chapter 1, Getting Started.
Additionally, an IDE that supports Scala programming, such as IntelliJ IDEA, with the Scala plugin should be installed globally.
The code for this recipe can be found in the ch14/elastic4s_sample
file; the referred class is DocumentExample
.
How to do it...
To manage documents, we will perform the following steps:
- We'll need to import the required classes to execute all the document's CRUD operations:
import com.sksamuel.elastic4s.ElasticDsl._ import com.sksamuel.elastic4s.circe._
- We need to create the client and ensure that the index and mapping exists:
object DocumentExample extends App with ElasticSearchClientTrait...