ElasticSearch mapping(类似于数据库表中的各个字段定义)

1、创建索引,定义mappings属性。

类型为keyword是不会被分词的。

index: 默认为true,设置为false,那么这个字段就不会被索引

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

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"
}

  

原文地址:https://www.cnblogs.com/linlf03/p/12775287.html