美文网首页
Elasticsearch

Elasticsearch

作者: 黄海佳 | 来源:发表于2020-07-16 14:57 被阅读0次

    基本

    从ElasticSearch6.X开始,官方准备废弃Type了。对应数据库,对ElasticSearch的理解如下

    • ElasticSearch ->数据库
    • 索引Index -> 表
      由具有相同结构(字段Field)的文档Document组成。每个索引都有自己的mapping定义,用于定义字段名和类型。
    常见数据类型
    - 字符串:text,keyword
    - 数据型:long,integer,short,byte,double,float,half_float,scaled_float
    - 布尔:boolean
    - 日期:date
    - 二进制:binary
    - 范围类型:integer_range,float_range,long_range,double_range,date_range
    
    • 文档Document -> 记录
      用户存储在es中的数据文档,JSON对象,由字段Field组成。
      ES要求每个文档有唯一ID,用户可自行指定(推荐),若未指定,ES自动生成唯一文档ID。具体操作API见下方

    • 字段Field ->列字段

    • 字段定义mapping -> 表结构定义schema

    基本语法

    • 创建和查看索引API
    PUT 方法
    {
        "aliases": {},
        "mappings": {
          "doc": {
            "properties": {
              "delay": {
                "type": "float"
              },
              "localhost": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "message": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "remotehost": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "time": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          }
        },
        "settings": {
          "index": {
            "number_of_shards": "5",
            "number_of_replicas": "1"
          }
        }
    }
    
    image.png

    参考

    https://www.cnblogs.com/wwcom123/p/10410124.html
    https://blog.csdn.net/laok186/article/details/89448169

    相关文章

      网友评论

          本文标题:Elasticsearch

          本文链接:https://www.haomeiwen.com/subject/iueccktx.html