简单ElasticSearch输入-拒绝标测更新最终标测将有1种以上类型:[_文件,文件]

sigwle7e  于 2023-01-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(102)

我试图发送数据到elasticsearch,但是遇到了一个问题,我的数字字段只显示为字符串。
步骤1.添加索引和Map

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

{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "HH:mm yyyy-MM-dd"
      },
        "data": {
        "type":   "integer"
      }
    }
  }
}

结果:

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "core_060619"
}

步骤2.添加数据

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

{
  "test" : [ {
    "data" : "119050300",
    "date" : "00:00 2019-06-03"
  } ]
}

结果:

{
    "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
}
eufgjt7s

eufgjt7s1#

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

ElasticSearch6.+

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"
        }
      }
    }
  }
}

由于我们创建了具有doc类型文档的Map,现在我们可以通过简单地添加/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"
  } ]
}

ElasticSearch7.+

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

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" 
        }
      }
    }
  }
}

Removal of mapping types

相关问题