(一)Elasticsearch 索引

es索引与mysql数据库对比

对比图

1. 索引数据类型

  • text 文本类型,text类型如果不显示指定映射的字段属性,默认是使用标准分词器进行分词,一般数据类型是text要么显示指定分词器,要么不分词,一般不使用默认的分词器(除非文本是纯英文)7.0后只能创建一个type -“doc”

  • keyword 如果数组中的值是字符串,最好使用keyword, 它不会对字符串进行分词

  • data 支持的格式有:可以通过format定义日期的数据格式,也支持毫秒数

  • geo-point: 支持经纬度存储和距离范围检索

  • ip 即支持ipv4也支持ipv6

  • geo-shape:支持任意图形范围的检索,例如矩形和平面多边形

  • nested : 嵌套对象, 用于数组中的元素是对象的[{}, {}]

  • boolean

  • float

  • double

  • byte

  • short

  • integer

  • long

  • object

  • mapping

    PUT users
    {
        "mappings" : {
          "properties" : {
            "firstName" : {
              "type" : "text"
            },
            "lastName" : {
              "type" : "text"
            },
            "mobile" : {
              "type" : "text",
              "index": false
            }
          }
        }
    }
    
    #files
    PUT user_files
    {
        "settings": {
            "max_result_window": 100000,
            "number_of_shards": 2,
            "number_of_replicas": 1
        },
        "mappings": {
            "_source": {
                "enabled": true
            },
            "properties": {
                "file_name": {
                    "type": "text",
                    "analyzer": "ik_max_word"
                },
                "file_extension": {
                    "type": "keyword"
                },
                "id":{
                    "type":"long"
                },
                "user_id":{
                    "type":"long"
                },
                "file_id":{
                    "type":"long"
                },
                "folder_id":{
                    "type":"long"
                },
                "file_size":{
                    "type": "long",
                    "index": false
                },
                "transition_state":{
                    "type":"boolean",
                    "index": false
                },
                "file_type":{
                    "type":"integer"
                },
                "edoc_auth":{
                    "type":"integer",
                    "index": false
                },
                "isdel":{
                  "type":"boolean"
                }
            }
        }
    }
    
        
    
  • index false不索引文档

  • setting

"settings": {
        "number_of_shards": 2,         // 每个索引的主分片数,默认值是 5 。这个配置在索引创建后不能修改。
        "number_of_replicas": 1        // 每个主分片的副本数,默认值是 1 。对于活动的索引库,这个配置可以随时修改
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容