ES索引的mappings映射

索引分词概念

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

创建索引的同时创建mappings

PUT     /index_str
{
    "mappings": {
        "properties": {
            "realname": {
            	"type": "text",
            	"index": true
            },
            "username": {
            	"type": "keyword",
            	"index": false
            }
        }
    }
}

查看分词效果

GET         /index_mapping/_analyze
{
	"field": "realname",
	"text": "imooc is good"
}

尝试修改

POST        /index_str/_mapping
{
    "properties": {
        "name": {
        	   "type": "long"
        }
    }
}

为已存在的索引创建或创建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:文字类需要被分词被倒排索引的内容,比如商品名称,商品详情,商品介绍,使用text。
  • keyword:不会被分词,不会被倒排索引,直接匹配搜索,比如订单状态,用户qq,微信号,手机号等,这些精确匹配,无需分词。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值