Angel S. Moreno
Angel S. Moreno

Reputation: 3971

Can Elasticsearch make suggestions for mapping?

Playing around with Elasticsearch I added a document to my index called "pets", that looks like this:

{
    "name" : "Piper",
    "type" : "dog"
}

Then I added a second document:

{
    "name" : "Max",
    "type" : "dog",
    "breed": "Scottish Terrier"
}

Now, I understand that the mapping of my "pets" index is initially created based on my first document ( unless i define a mapping at some point ). However, I am curious to know if ES can suggest a mapping based on the existing data ( like MySQL's "Propose table structure" ) or maybe update the mapping automatically.

Upvotes: 0

Views: 96

Answers (1)

Alistair Jones
Alistair Jones

Reputation: 583

Yes, ElasticSearch will automatically update the mapping.

Sometimes the language in the ElasticSearch documentation makes it sound like once the mapping is set, it cannot be changed. This is only true for the existing fields. Any additional fields will be automatically assigned a type and added to the mapping.

Remember you can always check the mapping of an index with the get mapping API: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html

For example, with the example you have above, after your first "pet" document the mapping is:

{
   "my_index": {
      "mappings": {
         "pet": {
            "properties": {
               "name": {
                  "type": "string"
               },
               "type": {
                  "type": "string"
               }
            }
         }
      }
   }
}

And after the second "pet" document, your mapping is:

{
   "my_index": {
      "mappings": {
         "pet": {
            "properties": {
               "breed": {
                  "type": "string"
               },
               "name": {
                  "type": "string"
               },
               "type": {
                  "type": "string"
               }
            }
         }
      }
   }
}

I'm not familiar with MySQL's propose table structure, so I can't comment on that...

Upvotes: 2

Related Questions