PUT /索引库名/_mapping
{
"properties":{
新字段名":{
"type": "integer"
}
}
}
properties 特性
索引库和mapping一旦创建无法修改,但是可以添加新的字段,语法如下:
PUT /索引库名/_mapping
{
"properties":{
"新字段名":{type": "integer"}
}
}
POST test/test/_mapping
{
"test": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}
上面的命令,是定义test索引下test类型的映射。其中定义了_all字段的分析方法,以及content属性的分析方法。
这里介绍下什么是_all字段,其实_all字段是为了在不知道搜索哪个字段时,使用的。es会把所有的字段(除非你手动设置成false),都放在_all中,然后通过分词器去解析。当你使用query_string的时候,默认就在这个_all字段上去做查询,而不需要挨个字段遍历,节省了时间。
字段 | 含义 | 释义 |
---|---|---|
properties | 定义了特定字段的分析方式 | 在上面的例子中,仅仅设置了content的分析方法。 |
type | 字段的类型为string | 只有string类型才涉及到分词,像是数字之类的是不需要分词的。 |
store | 定义字段的存储方式 | no代表不单独存储,查询的时候会从_source中解析。 |
store | 定义字段的存储方式 | 当你频繁的针对某个字段查询时,可以考虑设置成true。 |
term_vector | 定义了词的存储方式,with_position_offsets,意思是存储词语的偏移位置,在结果高亮的时候有用。 | |
analyzer | 定义了索引时的分词方法 | |
search_analyzer | 定义了搜索时的分词方法 | |
include_in_all | 定义了是否包含在_all字段中 | |
boost | 跟计算分值相关的 |