Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using explicit mapping creation


If you consider an index as a database in the SQL world, a mapping is similar to the table definition.

ElasticSearch is able to understand the structure of the document that you are indexing (reflection) and creates the mapping definition automatically (explicit mapping creation).

Getting ready

You will need a working ElasticSearch cluster, an index named test (see the Creating an index recipe in Chapter 4, Basic Operations), and basic knowledge of JSON.

How to do it...

To create an explicit mapping, perform the following steps:

  1. You can explicitly create a mapping by adding a new document in ElasticSearch:

    • On a Linux shell:

      #create an index
      curl -XPUT http://127.0.0.1:9200/test
      #{acknowledged":true}
      
      #put a document
      curl -XPUT http://127.0.0.1:9200/test/mytype/1 -d '{"name":"Paul", "age":35}'
      # {"ok":true,"_index":"test","_type":"mytype","_id":"1","_version":1}
      
      #get the mapping and pretty print it
      curl –XGET http://127.0.0.1:9200/test/mytype/_mapping?pretty=true...