实验原理
elasticsearch mapping 简介
Mapping 对应数据库里的表定义,我们都知道数据库表有各种字段每种字段使用场景是不一样,mapping 中字段也类似数据库字段,定义形式不同搜索场景也不同 ,mapping 还有一些其他的含义,mapping 不仅告诉 ES 一个 field 中是什么类型的值,它还告诉 ES 如何索引数据以及数据是否能被搜索到,Mapping 是对于 index 上每种 type 的定义。
mapping 的字段几种定义解释
mapping 字段定义的使用,我们下面针对常用的进行说明
index: “analyzed” //分词,不分词是:not_analyzed ,设置成 no,字段将不会被索引
analyzer: “ik” //指定分词器
search_analyzer: “ik” //设置搜索时的分词器,默认跟 ananlyzer 是一致的
下面我们同 java 的方式创建 mapping 并且通过 head 插件查看
实验步骤
创建 mapping
在syl_es项目的com.syl.es下新建 CreateMapping 类
image.png
编写 mapping 方法,具体代码如下:
package com.syl.es;
import java.net.InetAddress;
import org.elasticsearch.action.admin.indices.mapping.pu