Elasticsearch Index Mapping write, view, and modify

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.