Object数据类型及手动创建mapping

1.首先创建一个索引

PUT /lib5/
#Object类型
{
  "settings":{
      "index":{
        "number_of_shards": 5,
        "number_of_replicas": 0
        }
     }
}

2.插入数据

PUT /lib5/person/1
{
  "name":"Tom",
  "age":25,
  "birthday":"1985-12-12",
  "address":{
    "country":"china",
    "province":"guangdong",
    "city":"shenzhen"
  }
}

3.查看自动创建的mapping

GET /lib5/person/_mapping
{
  "lib5": {
    "mappings": {
      "person": {
        "properties": {
          "address": {
            "properties": {
              "city": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "country": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "province": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "age": {
            "type": "long"
          },
          "birthday": {
            "type": "date"
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

4.底层存储格式

{
  "name":["Tom"],
  "age":[25],
  "birthday":["1985-12-12"],
    " address.country":["china"],
    "address.province":["guangdong"],
    "address.city":["shenzhen"]
}

5.手动创建mapping

PUT /lib6
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 0
  },
  "mappings": {
    "books":{
      "properties": {
        "title":{"type": "text"},
        "name":{"type": "text","analyzer": "standard"},
        #index:false,禁止倒排索引
        "publish_date":{"type": "date","index": false},
        "price":{"type": "double"},
        "number":{"type": "integer"}
      }
    }
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。