elasticsearch建立mapping-相当于sql的表字段设置
首页->学习资料->微服务治理->elasticsearch 关键词: 发布时间:2020-04-05 05:57:42 浏览次数:2400

由于有些字段要进行全文搜索(类似于sql的like查询,但又不同,他是会进行分词再进行类似sql的like查询的)


先查看indice是否建立成功:

get https://es地址/_cat/indices


查看安装的分词器:

get https://es地址/_cat/plugins

返回如下:这里装了icu及ik两个,全者用于东南亚地区小语种分词,后者是用于中文分词
node-1 analysis-icu 7.6.0
node-1 analysis-ik  7.4.0


建立mapping前需要了解mapping字段类型及作用,这里列出一些常用的:

数据类型
text:会用分词器进行分词全文索引,不用于聚合及排序
keyword:不会进行分词,相当于sql中的index索引,可以用排序及聚合,常用于唯一性字段,如:邮箱,邮编等
geo_point:地理位置,可以用计算与某坐标点的距离,或指定一个区域的坐标,找出此域名内的所有坐标点;
	需要注意的是,如果是数组格式时,顺序是【经度,纬度】,如果是对像或字符串,则是【纬度,经度】
数值类型:不可分词
long,integer,short,byte,double,float,half_float,scaled_float
数组:
在Elasticsearch中,数组不需要专用字段数据类型。
默认情况下,任何字段都可以包含零个或多个值,但是数组中的所有值都必须是相同的数据类型

term:精确查询,相当于sql中的等于,不要将它用于text类型的字段上;
terms:精确查询,相当于sql中的in操作,不要将它用于text类型的字段上;
match:非精确查询,常用于text类型字段上,如果字段未指定分词器将采用默认的分词器


建立mapping

{
        "properties": {
            "id": {
                "type": "integer"
            },
            "tel": {
                "type": "keyword"
            },
            "name": {
                "type": "text",
                "analyzer":"ik_max_word",
                "search_analyzer":"ik_max_word"
            },
            "sex": {
                "type": "integer"
            },
            "city_id": {
                "type": "integer"
            },
            "city_name": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            },
            "location": {
                "type": "geo_point"
            },
            "create_time": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
            },
            "address": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}


查看mapping结构:

get https://es地址/student/_mapping


赞:(0)
踩:(0)
相关文章
elasticsearch插入时报错:invalid
无法访问虚拟机上的elasticsearch
elasticsearch scroll方式查询时sc
elasticsearch批量更新数据
centos7.4下安装elasticsearch
php中elasticsearch scroll方式查
Elasticsearch 实时分布式搜索分析
Elasticsearch 权威指南(中文版)
elasticsearch查询实例-模拟数据
elasticsearch-建立indice(相当于s
热门文章
win7中将文件拷贝到虚拟机linux下
phpexcel设置行高及列宽,背景颜色,
rabbitmq无法启动
intellij idea不显示git push按钮
php7中使用mongodb的aggregate进行
centos7.4 64位下swoole安装及配置
laravel页面静态化的方法
navicate连接mycat报1184错误
单点登录sso原理及php实现方式及de
devops-jenkins容器为pending状态
好评文章
phpexcel设置行高及列宽,背景颜色,
php7中使用mongodb的aggregate进行
intellij idea打开文件所在文件夹
windows下使用MongoDB Compass Com
win7中将文件拷贝到虚拟机linux下
laravel 中悲观锁 & 乐观锁的使用
单点登录sso原理及php实现方式及de
navicate连接mycat报1184错误
rabbitmq无法启动
laravel整合dingo/api方法步骤:jwt
标签
rabbitmq mysql备份 elasticsearch golang swoole
我的项目
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
站点信息
建站时间:2011年
文章数:607篇
浏览数:940840
粤ICP备18028092号-1  微信:hurong241