如何在“ Elasticsearch”上创建元数据?

时间:2019-10-21 02:16:41

标签: elasticsearch

我正在使用Elasticsearch 6.8。而且我想在索引上保存一些meta数据。该索引已经存在。我遵循了这份文档https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#add-field-mapping

curl "http://localhost:9200/idx_1/_mapping"

{
  "idx_1": {
    "mappings": {
      "1": {
        "properties": {
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

为了创建_meta数据,我需要首先创建映射类型。

然后我运行以下代码来为_meta创建一个version映射类型。

curl -X PUT -H 'Content-Type: application/json'  "http://localhost:9200/idx_1/_mapping" -d '
 {"_meta": { "version": {"type": "text"}}}'

我遇到了以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: mapping type is missing;"
      }
    ],
    "type": "action_request_validation_exception",
    "reason": "Validation Failed: 1: mapping type is missing;"
  },
  "status": 400
}

它表示缺少映射类型。我已将type的版本指定为text。为什么说missing type

1 个答案:

答案 0 :(得分:0)

原来,我看错了文档版本。根据Elasticsearch6 https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping-meta-field.html的文档,正确的请求是:

curl -X PUT "http://localhost:9200/idx1/_mapping/_doc" -H 'Content-Type: application/json' -d '{"_meta": {"version": "1235kljsdlkf"}}'