write and view of mapping
First create an index:
-XPOST "http://127.0.0.1:9200/productindex"{"acknowledged":true}
Now only one index is created, and the mapping is not set to look at the contents of the index mapping:
-XGET "http://127.0.0.1:9200/productindex/_mapping?pretty" { "productindex" : { "mappings" : { } }}
You can see that mapping is empty, we have created only one index, and no mapping configuration, mapping is naturally empty.
The following gives Productindex this index plus a type,type name for product
, and set mapping:
Curl-xpost"Http://127.0.0.1:9200/productindex/product/_mapping?pretty"-d ' {"Product": {"Properties": {"title": {"Type": "string", "store": "yes"}, "description": { "type": "string", "index": "not_analyzed"}, "price": { "type": "Double"}, "OnSale": { "type": "boolean"}, "type": {" type ": " integer "}, " CreateDate ": {" type ": " Date "}}} ' {" acknowledged ": true}
In the above operation, we add a type to Productindex and write the mapping information of the product, and see again:
Curl-xget"Http://127.0.0.1:9200/productindex/_mapping?pretty" {"Productindex": {"Mappings": {"Product": {"Properties": {"CreateDate": {"Type":"Date","format": "strict_date_optional_time| | Epoch_millis "}, " description ": { " type ": " string ", " index ": " not_analyzed "}, " OnSale ": {
"type": "
Boolean"}, "price": { "type": "Double"}, "title": { "type": "string", c16> "Store": true}, "type": { "type": "Integer"}}}}}
Modify Mapping
If you want to add a field to product, you need to modify mapping and try it:
"http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d ‘{ "product": { "properties": { "amount":{ "type":"integer" } } } }‘{ "acknowledged" : true}
Added success.
If you want to modify the type of a field, for example, the type of the OnSale field is Boolean, and now you want to modify it to a string type, try:
"http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d ‘{ "product": { "properties": { "onSale":{ "type":"string" } } }}‘
Return Error:
{ "error ": {" root_cause ": [{"type": " Illegal_argument_exception "," reason ": "Mapper [OnSale] of different type, Current_type [Boolean], Merged_type [string]"}], "type ": " Illegal_argument_exception "," Reason ": " mapper [OnSale] of different type, Current_type [Boolean ], Merged_type [string] "}," status ":
Why can't I modify the type of a field? The reason is that after the type of a field has been modified, all data for that field needs to be re-indexed. Elasticsearch the underlying use of the Lucene library, the field type modified after the index and search to involve word segmentation, and so on, do not allow the modification of the type in my opinion is in accordance with the Lucene mechanism.
Here is a blog about modifying the mapping field, a relatively clear narrative: Elasticsearch of the pit-dad-record a mapping field modification process, you can refer to.
Transferred from: http://blog.csdn.net/napoay/article/details/52012249
(go) elasticsearch Index mapping write, view, and modify