索引映射管理

API允许向索引(index)添加文档类型(type),或者向文档类型中添加字段(field)
elasticsearch支持文档中字段的许多不同类型,点击访问,下面列举一些常用类型:

  1. 字符串类型
    textkeyword
  2. 数值类型
    long, integer, short, byte, double, float, half_float, scaled_float
  3. 日期类型
    date
  4. 布尔值类型
    boolean
  5. 二进制类型
    binary
  6. 范围类型
    integer_range, float_range, long_range, double_range, date_range

添加映射

请求:PUT http://127.0.0.1/9200/book/_mapping/novel(novel为类型,相当于一张数据库表)
参数


    {       "properties":{
                "bookname":{
                    "type":"text"
                },
                "author":{
                    "type":"keyword"
                },
                "price":{
                    "type":"double"
                },
                "press":{
                    "type":"text"
                },
                "num":{
                    "type":"integer"
                },
            
                "publicationdate":{
                    "type":"date",
                    "format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                }

}
}

注意:在同一个索引的不同类型中,相同名称的字段必须有相同的映射.

获取映射

请求:GET http://127.0.0.1/9200/books/_mapping/novel
返回值

{
    "books": {
        "mappings": {
            "novel": {
                "properties": {
                    "author": {
                        "type": "keyword"
                    },
                    "bookname": {
                        "type": "text"
                    },
                    "num": {
                        "type": "integer"
                    },
                    "press": {
                        "type": "text"
                    },
                    "price": {
                        "type": "double"
                    },
                    "publicationdate": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                    }
                }
            }
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容