Unnamed mapping for PUT

The mapping documentation states that the following code will create a tweet type on the twitter index with the specified mapping

$ curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '
{
    "tweet" : {
        "properties" : {
            "message" : {"type" : "string", "store" : true }
        }
    }
}
'

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html

The following also appears to work:


$ curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '
{
   "properties" : {
       "message" : {"type" : "string", "store" : true }
  }
}

Is this behavior by design? It doesn't appear to be documented that you can just send the mapping without having a property name matching the type. We are currently using this behavior, but we'd like to be able to count on its existence in the future. If this is not by design, feedback would be appreciated.

Also note that the following works:


$ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
   "properties" : {
       "message" : {"type" : "string", "store" : true }
  }
}
'

Unless my eyes deceive me, these are the same? (The first two that is)

Note that the second example doesn't have a named property of tweet in the object being PUT

Ahh you're right, early morning blunder :wink:

Sending invalid json isn't always guaranteed to work. It does now sometimes
like you saw. Not sure about the mapping with and without the name.
Personally I'd like only the without form to work when you've already put
it in the path but I don't know what the long term plan is.

Personally I'd like only the without form to work when you've already put it in the path but I don't know what the long term plan is.

Yeah this is what I was hoping for as well, since the type is in the URL. This is also useful if you have multiple types that use the same mapping. I think we could set something up that uses a default template, but I like how explicit the above is.