简体   繁体   中英

Confusion between mappings and types in ElasticSearch

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM