Elasticsearch Index settings and Mappings: How to create Index mapping and settings (Elasticsearch and Kibana Devtool)

For illustration purpose we generally index document and elasticsearch(ELS) does settings and mappings creation for us. But in production environment we generally first create Index's settings and mapping. In ELS mapping has significance however in ELS 7 mapping will be irrelevant as Type will be decommissioned.
In this post we will see how to create Index settings and mapping in strict mode before creating very first document. Settings node primarily specify number of shards & number of replica. Mapping specify data types of document and analyzers details.

What is strict mode mapping ?
By default elasticsearch allows incremental change in document with new fields other than fields specified initially while setting up mapping node. i.e: "dynamic" : "false". Elasticsearch figure out data type dynamically and add it in mapping node.
In order to restrict specific set of fields in doc specified in mapping, we have to use
"dynamic" : "strict". Below PUT command creates mapping with dynamic = strict (highlighted in yellow)
ELS has two values for dynamic field.
dynamic : false - indexing field will be ignored
dynamic : strict  - indexing field will throw error

Create Index mapping and settings : Below PUT command creates index customers with settings and mapping details. By default ELS setup number of shards = 5, we have overwritten it to 2.
In mapping nodes we have to specify list of fields and analyzer details(fields where we want analysis to be carried out). name is of type text and we instruct to use standard analyzer for it.
Note:- When we have to use custom analyzer for analysis, custom analyzer is declared under settings node.

PUT /customers
{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1
  },
  "mappings": {
    "online" :{
      "dynamic": "strict",
      "properties":{
        "gender" :{
          "type": "text",
          "analyzer" : "standard"
        },
        "age":{
            "type": "integer"
        },
        "total_spent":{
           "type": "float"
        },
        "is_new":{
           "type" : "boolean"
        },
        "name":{
           "type": "text",
           "analyzer" : "standard"
        },
        "address": {
          "type" : "text",
          "fields":{
            "keyword":{
              "type" : "keyword",
              "ignore_above":  256
            }
          }
        }
      }
    }
  }
}
Show response

Index customers document of type Online: Index document successfully as it followed mapping specs (all document fields are specified in mapping)
PUT /customers/online/176
{  
        "gender" : "male",
        "age":25,
        "total_spent":1298.69,
        "is_new":false,
        "name": "Nikhil",
        "address" : "Windsor prime, Bangalore"
}
Show response

Index customers document with additional fields : Here we will add locale field in document and expect elastic search will not index document successfully, it should throw error - strict_dynamic_mapping_exception. Remember "dynamic" : "strict" will enforce indexing to follow mapping specs.
PUT /customers/online/176
{  
        "gender" : "male",
        "age":25,
        "total_spent":1298.69,
        "is_new":false,
        "name": "Nikhil",
        "address" : "Windsor prime, Bangalore",
        "locale" : "en-US"
}
Show response

How to add restriction on existing index type ? Using _mapping with PUT command we can change dynamic value of a given type.
PUT /customers/_mapping/online
{
    "dynamic": "strict"
}
Show response

36 Comments

  1. Great blog thanks for sharing Instagram and Facebook have provided an amazing place for new brands to grow and flourish. We can find the perfect niche for your brand on the best social media platforms. Marketing through social media brings forth global audience without all these physical boundaries. Analyze and take over the competition with ease with Adhuntt Media’s digital marketing tools and strategies.
    digital marketing company in chennai

    ReplyDelete
  2. Nice blog thanks for sharing You have come to the right place. Karuna Nursery Gardens is the ideal place to begin your journey into landscape gardening. Our specialists have built some of the finest landscape garden in Chennai that too at the best price and amazing service.
    plant nursery in chennai

    ReplyDelete
  3. Excellent blog thanks for sharing Looking for the best place in Chennai to get your cosmetics at wholesale? The Pixies Beauty Shop is the premium wholesale cosmetics shop in Chennai that has all the international brands your salon deserves.
    beauty Shop in Chennai

    ReplyDelete
  4. Amazing post, thanks for publishing!

    ReplyDelete
  5. python interview questions and answers for testers


    Important Python Interview Questions and Answers for freshers and experienced to get your dream job in Python! 101 Python Basic Interview Questions for Freshers

    ReplyDelete
  6. I read your post and got it quite informative. I couldn't find any knowledge on this matter prior to. I would like to thanks for sharing this article here.African Cosmetics Online Shop

    ReplyDelete
  7. Thanks for this great post! I am using your article for my reference. Keep sharing more such valuable articles.
    HTML5 course
    HTML course
    PHP Training in Velachery
    Software Testing Training in Velachery

    ReplyDelete
  8. Great blog.thanks for sharing such a useful information
    Big Data Hadoop Training

    ReplyDelete
  9. Great blog.thanks for sharing such a useful information
    QTP Training

    ReplyDelete
  10. This post is so interactive and informative.keep update more information...
    dot net training in anna nagar
    Dot net training in Chennai

    ReplyDelete
  11. This post is so interactive and informative.keep update more information...
    PHP Training in Tambaram
    PHP Training in Tambaram

    ReplyDelete
  12. Awesome Blog. Thanks for sharing such a worthy information. Keep update like this...
    Why Learn Data Science is Important
    why data science is important in today’s world

    ReplyDelete
  13. This post is so interactive and informative.keep update more information...
    Java Training in Tambaram
    java course in tambaram

    ReplyDelete
  14. Great information. The above content is very interesting to read. Looking for the best online phonics classes for kindergarten, Ziyyara Edutech’s online phonics classes for kindergarten are designed to conquer the challenges like limited hands-on activities and pronunciation issues with expert guidance.
    visit Phonics for kindergarten

    ReplyDelete
  15. This is very nice post.I’m happy to see some great article on your site. Ziyyara Edutech spoken English classes in Saudi Arabia provide the platform for you to achieve linguistic excellence.
    For Book a demo now English language courses in Saudi Arabia

    ReplyDelete
  16. Really great post, Thank you for sharing This knowledge.Excellently written article, Unlock academic excellence with Ziyyara Edutech's specialized online tuition for Class 11.
    For more info Contact us: +91-9654271931, +971-505593798 or visit Online tuition for 11th class

    ReplyDelete
  17. Thank you for taking the time and sharing this information with us. Embark on a seamless online learning journey for your 2nd grader with our tailored home tuition classes.
    For more info visit Online tuition for class 2 near me

    ReplyDelete
  18. Packaging has been revolutionised by China Bopp adhesive tape film manufacturers films, which provide dependable and secure sealing options. The product will be kept intact or just minimally damaged during transportation since it is resistant to a broad variety of environmental conditions. Management of the supply chain and logistics are aided by this.

    ReplyDelete
Previous Post Next Post