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