ElasticSearch映射问题-嵌套到非嵌套

时间:2020-04-14 15:00:27

标签: elasticsearch elasticsearch-mapping

我正在为计算机视觉应用程序生成的数据创建映射。但是,当我尝试将示例数据消息推送到ElasticSearch时遇到错误。我已经阅读了很多其他人都曾遇到过这个问题的论坛。有些人已经解决了他们的问题,但是我已经尝试了所有我想尝试的事情。我实际上认为可能有一个简单的解决方案,但对于Elastic而言我是相对较新的 搜索。

使用以下命令成功创建索引和映射:

PUT vision_events
{
  "settings" : {
        "number_of_shards" : 5
    },
  "mappings" : {
        "properties": {
          "camera_id": {
            "type": "text",
            "fields": {
              "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "hit_counts": {
          "type": "long"
        },
        "id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "intersection": {
          "type": "boolean"
        },
        "label": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "locations": {
          "type" : "nested",
           "properties": {
            "coords" : {
                "type" : "float"
            },
            "location": {
              "type": "text"
            },
            "street_segment": {
              "type": "text"
            },
            "timestamp": {
              "type": "date"
            }
          }
        },
        "pole_id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "timestamp": {
        "type":   "date"
        }
      }
    }
}

完成后,我将继续验证映射是否正确。我推送以下示例数据:

POST /vision_events/1?pretty=true
{
  "pole_id": "mlk-central-2",
  "camera_id": "mlk-central-cam-2",
  "intersection": true,
  "id": "644d1c06-4c60-4ed8-93b4-1aa79b87a622",
  "label": "car",
  "timestamp": 1586838108683,
  "locations": [
    {
      "timestamp": 1586838109448,
      "coords": 1626.3220383482665,
      "street_segment": "None"
    },
    {
      "timestamp": 1586838109832,
      "coords":  1623.3129222859882,
      "street_segment": "None"
    }
  ],
  "hit_counts": 2
}

这会产生以下错误:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "object mapping [locations] can't be changed from nested to non-nested"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "object mapping [locations] can't be changed from nested to non-nested"
  },
  "status" : 400
}

locations字段是“对象”的列表,其中包含以下字段:坐标,位置,street_segment和时间戳。邮件的位置长度不同。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

放置未更改的映射:

PUT vision_events
{"settings":{"number_of_shards":5},"mappings":{"properties":{"camera_id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"hit_counts":{"type":"long"},"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"intersection":{"type":"boolean"},"label":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"locations":{"type":"nested","properties":{"coords":{"type":"float"},"location":{"type":"text"},"street_segment":{"type":"text"},"timestamp":{"type":"date"}}},"pole_id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"timestamp":{"type":"date"}}}}

根据POST结构from the docs插入单个文档:

POST /vision_events/_doc/1?pretty=true
{
  "pole_id": "mlk-central-2",
  "camera_id": "mlk-central-cam-2",
  "intersection": true,
  "id": "644d1c06-4c60-4ed8-93b4-1aa79b87a622",
  "label": "car",
  "timestamp": 1586838108683,
  "locations": [
    {
      "timestamp": 1586838109448,
      "coords": 1626.3220383482665,
      "street_segment": "None"
    },
    {
      "timestamp": 1586838109832,
      "coords": 1623.3129222859882,
      "street_segment": "None"
    }
  ],
  "hit_counts": 2
}