ElasticSearch mapping(索引的数据结构,类似于数据库表中的各个字段定义)
Posted on 2020-04-25 21:38 work hard work smart 阅读(842) 评论(0) 收藏 举报1、创建索引,定义mappings属性。
类型为keyword是不会被分词的。
index: 默认为true,设置为false,那么这个字段就不会被索引,不会被查询到。

创建好后,在http://localhost:9100/ 中查看索引的信息

类型为keyword,就不会被分词,如手机号,QQ号。
2、查看分词效果

返回如下:
{
"tokens": [
{
"token": "nick",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "is",
"start_offset": 5,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "a",
"start_offset": 8,
"end_offset": 9,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "good",
"start_offset": 10,
"end_offset": 14,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "man",
"start_offset": 15,
"end_offset": 18,
"type": "<ALPHANUM>",
"position": 4
}
]
}
3、增加索引的属性
增加id和age属性。默认是不能修改属性的,要先删除,在增加。

属性类型可以为以下几种
"properties": {
"birthday": {
"type": "date"
},
"score": {
"type": "float"
},
"sex": {
"type": "byte"
},
"is_teenger": {
"type": "boolean"
},
"id": {
"type": "long"
},
"relationship": {
"type": "object"
},
"money2": {
"type": "float"
},
"age": {
"type": "integer"
},
"money1": {
"type": "double"
},
"realname": {
"type": "text"
},
"username": {
"index": false,
"type": "keyword"
}
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!
浙公网安备 33010602011771号