url: /test1
method: PUT
params : {
"mappings": {
"type1": {
"properties": {
"user": {
"type": "string"
}
}
}
}
}
{
"error": {
"root_cause": [{
"type": "mapper_parsing_exception",
"reason": "No handler for type [string] declared on field [user]"
}],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [type1]: No handler for type [string] declared on field [user]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "No handler for type [string] declared on field [user]"
}
},
"status": 400
}
url: /test1
method: PUT
params : {
"mappings": {
"type1": {
"properties": {
"user": {
"type": "text",
}
}
}
}
}
(1)string
string类型在ElasticSearch 旧版本中使用较多,从ElasticSearch 5.x开始不再支持string,由text和keyword类型替代。
(2)text
当一个字段是要被全文搜索的,比如Email内容、产品描述,应该使用text类型。设置text类型以后,字段内容会被分析,在生成倒排索引以前,字符串会被分析器分成一个一个词项。text类型的字段不用于排序,很少用于聚合。
(3)keyword
keyword类型适用于索引结构化的字段,比如email地址、主机名、状态码和标签。如果字段需要进行过滤(比如查找已发布博客中status属性为published的文章)、排序、聚合。keyword类型的字段只能通过精确值搜索到。
url: /test1
method: PUT
params : {
"mappings": {
"type1": {
"properties": {
"user": {
"type": "text",
"index": "not_analyzed"
}
}
}
}
}
{
"error": {
"root_cause": [{
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [type1]: Could not convert [user.index] to boolean"
}],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [type1]: Could not convert [user.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Could not convert [user.index] to boolean",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
}
},
"status": 400
}
url: /test1
method: PUT
params : {
"mappings": {
"type1": {
"properties": {
"user": {
"type": "text",
"index": false
}
}
}
}
}
mapping parameters中的index只能接收一个bool值,true或者false
# POST
url: /_analyze/
method: POST
params : {
"tokenizer": "keyword",
"token_filters": [
"lowercase"
],
"char_filters": [
"html_strip"
],
"text": "this is a test"
}
{
"error": {
"root_cause": [{
"type": "illegal_argument_exception",
"reason": "Unknown parameter [token_filters] in request body or parameter is of the wrong type[START_ARRAY] "
}],
"type": "illegal_argument_exception",
"reason": "Unknown parameter [token_filters] in request body or parameter is of the wrong type[START_ARRAY] "
},
"status": 400
}
# POST
url: /_analyze/
method: POST
params : {
"tokenizer": "keyword",
"filter": [
"lowercase"
],
"char_filter": [
"html_strip"
],
"text": "this is a test"
}
# POST
url: /meta_test/_search/
method: POST
params : {
"query": {
"match": {
"_all": "yan shaowen"
}
}
}
{
"took": 264,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
现有的数据为
{
"_index": "meta_test",
"_type": "_doc",
"_id": "e6uod2cBb7ER3WX6wipL",
"_version": 1,
"_score": 1,
"_source": {
"first_name": "yan",
"last_name": "shaowen",
"date_of_birth": "1993-03-14"
}
}
# POST
url: /meta_test/_doc/_mapping/
method: PUT
params : {
"_doc": {
"_all": {
"enabled": true
}
}
}
{
"error": {
"root_cause": [{
"type": "illegal_argument_exception",
"reason": "Enabling [_all] is disabled in 6.0. As a replacement, you can use [copy_to] on mapping fields to create your own catch all field."
}],
"type": "illegal_argument_exception",
"reason": "Enabling [_all] is disabled in 6.0. As a replacement, you can use [copy_to] on mapping fields to create your own catch all field."
},
"status": 400
}
{
"query": {
"query_string": {
"query": "yan shaowen"
}
}
}