ThoughtWorks欧亚创新工作室java学习笔记整理

索引映射管理

2019-06-12  本文已影响0人  _借东西的小人

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"
                    }
                }
            }
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读