栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【Elasticsearch系列】索引的mappings映射

【Elasticsearch系列】索引的mappings映射

索引的mappings映射 1、索引分词概念

index:默认true,设置为false的话,那么这个字段就不会被索引
引用官文:
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index.html

index

The index option controls whether field values are indexed. It accepts true or false and defaults to true. Fields that are not indexed are not queryable.

2、创建索引的同时创建Mappings
PUT     /index_str
{
    "mappings": {
        "properties": {
            "realname": {
            	"type": "text",
            	"index": true
            },
            "username": {
            	"type": "keyword",
            	"index": false
            }
        }
    }
}
3、查看分词效果
GET         /index_mapping/_analyze
{
	"field": "realname",
	"text": "imooc is good"
}
4、尝试修改(不可修改)
POST        /index_str/_mapping
{
    "properties": {
        "name": {
        	   "type": "long"
        }
    }
}
5、为已存在的索引创建Mappings
POST        /index_str/_mapping
{
    "properties": {
        "id": {
        	"type": "long"
        },
        "age": {
        	"type": "integer"
        },
        "nickname": {
            "type": "keyword"
        },
        "money1": {
            "type": "float"
        },
        "money2": {
            "type": "double"
        },
        "sex": {
            "type": "byte"
        },
        "score": {
            "type": "short"
        },
        "is_teenager": {
            "type": "boolean"
        },
        "birthday": {
            "type": "date"
        },
        "relationship": {
            "type": "object"
        }
    }
}

注:某个属性一旦被建立,就不能修改了,但是可以新增额外属性

主要数据类型
  • text, keyword, string
  • long, integer, short, byte
  • double, float
  • boolean
  • date
  • object
  • 数组不能混,类型一致
字符串

text:文字类需要被分词被倒排索引的内容
keyword:不会被分词,不会被倒排索引,直接匹配搜索

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/312710.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号