Elasticsearch

数据结构

  1. 数字类型
  • byte: 有符号的8位整数, 范围: [-128 ~ 127]
  • short: 有符号的16位整数, 范围: [-32768 ~ 32767]
  • integer: 有符号的32位整数, 范围: [-2^31 ~ 2^31-1]
  • long: 有符号的64位整数, 范围: [-2^63 ~ 2^63-1]
  • float: 32位单精度浮点数
  • double: 64位双精度浮点数
  • half_float: 16位半精度浮数
  • scaled_float: 缩放类型的的浮点数, 比如price字段只需精确到分, 57.34缩放因子为100, 存储结果为5734
  1. 字符串类型
  • text: 文本类型,会被分词,示例如下
{
    "properties": {
        "context": {
            "type": "text",
            "analyzer": "icu_analyzer"
        }
    }
}
  • keyword: 精确值,不会被分词,示例如下
{
    "properties": {
        "context": {
            "type": "keyword"
        }
    }
}
  1. 日期类型
  • date: 格式化日期的字符串,代表时间毫秒数的长整型数字,
    代表时间秒数的整数
  1. 布尔类型
  • boolean
  1. 二进制类型
  • binary
  1. 范围类型
  • integer_range: [-2^31 ~ 2^31-1]
  • long_range: [-2^63 ~ 2^63-1]
  • float_range: 32位单精度浮点数
  • double_range: 64位双精度浮点数
  • date_range: 日期类型范围
  • ip_range: IP值的范围, 支持IPV4和IPV6, 或者这两种同时存在
  1. 其他类型
    参考Elasticsearch的数据类型

数据操作

创建索引

  • api: /any_index
  • method: POST
  • body: json
{
  "mappings": {
    "dynamic": "false",
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "icu_analyzer"
      }
    }
  }
}

导入数据

  • api: /any_index/_bulk
  • method: POST
  • body: bulk file
{"index":{"_id":"1"}}
{"id": 1, "name": "123", "age": 3}
...