text类型:会进行分词;分词后建立索引;支持模糊查询;支持准确查询;不支持聚合查询。
keyword类型:不会分词;直接建立索引;支持模糊查询;支持准确查询;支持聚合查询。
1.查看索引类型结构
GET /my_index/_mapping
查询结果:
{
"my_index" : {
"mappings" : {
"_meta" : { },
"_source" : {
"includes" : [ ],
"excludes" : [ ]
}
"numeric_detection" : false,
"properties" : {
...
"my_field" : {
"type" : "text"
}
}
}
2.添加keyword类型
PUT /my_index/_mapping
{
"properties": {
"my_field": {
"type": "text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
结果:
{
"acknowledged" : true
}