10

Sorry, I'm new to ElasticSearch.

http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html

This document says you can "creates a mapping called tweet within the twitter index"

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

As someone told me on ES IRC channel, /twitter/tweet twitter=index, tweet=type

But what happens if I do the following?

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

If I already provided the type name in the url, why should i still provide a type name in the content? If I provide the type name in the content, why can't I just call some url like:

$ curl -XPUT 'http://localhost:9200/twitter/_mapping' -d '

While reading the doc, for me it says "creates a mapping called tweet within the twitter index", this means XXX is the mapping name and YYY is the type name.

Thus if there is a mapping name, there can normally be many "mappings" for an index

So, in the end, XXX and YYY are/should be the same?


It's not what i understand from the doc, but what I think is: - One index can have types - Types have a mapping Thus we don't create a mapping like the documentation says, but we create a type, that has a mapping, or we update the type's mapping no?

And on an index where I don't want to use any type (all documents indexed are the same kind of data), but I want to create a mapping for that index, am I supposed to handle that by creating only one type with its mapping, and always use that type (in the CouchDB river for example)?

Thanks

mt3
  • 2,654
  • 4
  • 26
  • 29
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419

1 Answers1

11

In the current version of elasticsearch search (0.19.4) "YYY" is ignored and mapping is assigned to the "XXX" type.

Indeed, you can think of creating mappings as creating types. Internally, types are represented in terms of mappings and documentation just reflects this behavior. If all your records have the same type, you should treat the index as an index with only one type. Type is used to "namespace" records of different types and therefore it's mandatory. An id itself doesn't uniquely identify a record. To identify a record in elasticsearch, you need to have index, type and id. This is why type is a required paramater for the get operation, for example. For other operations, if type is not specified, elasticsearch assumes that you want to perform the operation with records of all types.

Note, that types can also be created dynamically at any time by adding a record of a new type. So, an index with only one type is an index that doesn't have the second type yet.

imotov
  • 28,277
  • 3
  • 90
  • 82
  • Not sure if you know but it's possible to set all mappings during index creation and it has much more intuitive API. See Mappings section of this page: http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html – imotov Jun 05 '12 at 17:55
  • yes i've noticed it. But actually i'd like to create a CouchDB river and i don't think i can create the index + mapping with the CouchDB river. I guess i should create the index + mapping (1 step or 2) first and then the river. – Sebastien Lorber Jun 06 '12 at 08:13
  • what about my other question? if all my docs are of the same type inside my index, how am i supposed to handle the mapping for that index? – Sebastien Lorber Jun 06 '12 at 08:14
  • I have added the answer for this question. Let me know if it requires any additional clarification. – imotov Jun 06 '12 at 10:25