mapping——动态模板

Elasticsearch默认给字符类型为text和keyword的混合类型

1         "type": "text",
2             "fields": {
3               "keyword": {
4                 "type": "keyword",
5                 "ignore_above": 256
6               }
7             }

 

实际业务中,不是所有数据字段都需要进行分词的,可以将这部分数据字段的类型设置为keyword类型,需要分词的字段设置为text类型,进行分词。

 

 1 PUT user_four
 2 {
 3   "mappings": {
 4     "aa":{
 5       "dynamic_templates":[
 6         {
 7         "keyword":{
 8           "match_mapping_type":"string",
 9           "match":"usr_*",
10           "mapping":{
11             "type":"keyword"
12           }
13         }},
14        { "text1":{
15           "match_mapping_type":"string",
16           "unmatch":"usr_*",
17           "mapping":{
18             "type":"text"
19           }
20         }
21         }
22       ]
23   }
24 }
25 }
PUT user_four/aa/1
{
  "usr_id":"abc",
  "usr_name":"good",
  "address":"北京市昌平区"
}

GET user_four/_mapping

 1 {
 2   "user_four": {
 3     "mappings": {
 4       "aa": {
 5         "dynamic_templates": [
 6           {
 7             "keyword": {
 8               "match": "usr_*",
 9               "match_mapping_type": "string",
10               "mapping": {
11                 "type": "keyword"
12               }
13             }
14           },
15           {
16             "text1": {
17               "unmatch": "usr_*",
18               "match_mapping_type": "string",
19               "mapping": {
20                 "type": "text"
21               }
22             }
23           }
24         ],
25         "properties": {
26           "address": {
27             "type": "text"
28           },
29           "usr_id": {
30             "type": "keyword"
31           },
32           "usr_name": {
33             "type": "keyword"
34           }
35         }
36       }
37     }
38   }
39 }

 

posted on 2019-10-12 14:23  浅蓝色星光  阅读(343)  评论(0编辑  收藏  举报