Elasticsearch 基本映射失败

Elasticsearch basic mapping fails

我已经为 Elasticsearch 5.5.2 和 Kibana 安装了 Docker 容器。开始学习映射类型,通过xcurl创建索引如下代码:

{
  "mappings": {
    "user": { 
      "_all":       { "enabled": false  }, 
      "properties": { 
        "title":    { "type": "text"  }, 
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" }  
      }
    }
}

索引创建成功,我决定插入一些数据。当我尝试将字符串添加到整数字段 i.e. {"age": "hello"} 时,Elastic 显示错误(这意味着映射工作正常)。问题出在其他数据类型上:

1.It 在字符串字段中接受整数和浮点数(我认为这可能是因为隐式转换)。

2.It 在 age 字段中接受类似 22.4 的浮点数(当我使用 Kibana 或 xcurl 搜索时,age 字段内容显示为浮点数而不是整数,这意味着不进行从浮点数到整数的转换)

我做错了什么?

您是否尝试过禁用强制转换?可以在现场级别完成:

   {
     "mappings": {
       "user": { 
         "_all":       { "enabled": false  }, 
         "properties": { 
           "title":    { "type": "text"  }, 
           "name":     { "type": "text"  }, 
           "age":      { "type": "integer",
                         "coerce": false}  
         }
       }
   }

或所有字段在索引级别:

   "settings": {
       "index.mapping.coerce": false
     },
     "mappings": {
   ...