简单的弹性搜索输入 - 拒绝映射更新最终映射将有 1 种以上的类型:[_doc, doc]

Jim*_*mmy 3 elasticsearch

我正在尝试将数据发送到 elasticsearch,但遇到了一个问题,我的数字字段仅作为字符串出现。这些是我采取的步骤。

步骤 1. 添加索引和地图

PUT http://123.com:5101/core_060619/

{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "HH:mm yyyy-MM-dd"
      },
        "data": {
        "type":   "integer"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

结果:

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "core_060619"
}
Run Code Online (Sandbox Code Playgroud)

步骤 2. 添加数据

PUT http://123.com:5101/core_060619/doc/1

{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}
Run Code Online (Sandbox Code Playgroud)

结果:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Rejecting mapping update to [zyxnewcoreyxbl_060619] as the final mapping would have more than 1 type: [_doc, doc]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [zyxnewcoreyxbl_060619] as the final mapping would have more than 1 type: [_doc, doc]"
    },
    "status": 400
}
Run Code Online (Sandbox Code Playgroud)

dej*_*ich 6

您不能拥有超过一种类型的文档Elasticsearch 6.0.0+。如果您将文档类型设置为doc,那么您可以简单地添加另一个文档PUT http://123.com:5101/core_060619/doc/1PUT http://123.com:5101/core_060619/doc/2等等。

弹性搜索 6.+

PUT core_060619/
{
  "mappings": {
    "doc": {     //type of documents in index is 'doc'
     "properties": {
        "date": {
          "type":   "date",
          "format": "HH:mm yyyy-MM-dd"
        },
          "data": {
          "type":   "integer"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

由于我们创建了具有doc文档类型的映射,现在我们可以通过简单地添加/doc/_id以下内容来添加新文档:

PUT core_060619/doc/1
{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}


PUT core_060619/doc/2
{
  "test" : [ {
    "data" : "111120300",
    "date" : "10:15 2019-06-02"
  } ]
}  
Run Code Online (Sandbox Code Playgroud)

弹性搜索 7.+

类型已删除,但您可以使用自定义字段:

PUT twitter
{
  "mappings": {
    "_doc": {
      "properties": {
        "type": { "type": "keyword" }, 
        "name": { "type": "text" },
        "user_name": { "type": "keyword" },
        "email": { "type": "keyword" },
        "content": { "type": "text" },
        "tweeted_at": { "type": "date" }
      }
    }
  }
}

PUT twitter/_doc/user-kimchy
{
  "type": "user", 
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "shay@kimchy.com"
}

PUT twitter/_doc/tweet-1
{
  "type": "tweet", 
  "user_name": "kimchy",
  "tweeted_at": "2017-10-24T09:00:00Z",
  "content": "Types are going away"
}

GET twitter/_search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "user_name": "kimchy"
        }
      },
      "filter": {
        "match": {
          "type": "tweet" 
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

删除映射类型