Managing mappings
After creating an index, the next step is to add some mappings to it. We already learned how to include a mapping via the REST API in Chapter 3, Basic Operations. In this recipe, we will see how to manage mappings via a native client.
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
directory; the referred class is MappingExample
.
How to do it...
In the following code, we add a mytype
mapping to a myindex
index via the native client:
- We need to import the required classes:
import com.sksamuel.elastic4s.ElasticDsl._
- We define a class to contain our code and initialize the client and the index:
object MappingExample extends App with...