【问题标题】:ElasticSearch mapper to insert data in ESElasticSearch 映射器在 ES 中插入数据
【发布时间】:2022-11-11 00:27:14
【问题描述】:

我正在编写将数据插入弹性索引的映射器,但出现以下错误。

elasticsearch.BadRequestError: BadRequestError(400, 'mapper_parsing_exception', 'not_x_content_exception: 压缩器检测只能在某些 xcontent 字节或压缩 xcontent 字节上调用')

mapper = {"mappings":
    {
        "event_info": {"type": "nested",
                       "properties": {
                           "type_info": {"type": "text"},
                           "op_type": {"type": "text"},
                           "file_name": {"type": "text"},
                           "file_ext": {"type": "text"},
                           "process_id": {"type": "text"},
                           "time_stamp": {"type": "text"}
                       }
                       }
    }
}
data = [{'event_info': [{'type_info': 'INFO', 'op_type': 'WRITE', 'file_name': '0.txt', 'file_ext': '.txt', 'process_id': '1234', 'time_stamp': '2022-10-17 05:23:06.8620427 +0000 UTC'}]}]

需要为插入数据创建正确的映射器。任何帮助,将不胜感激。

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    使用 Elasticsearch 8.5.0,这对我有用。

    映射:

    {
      "mappings": {
          "properties": {
            "event_info": {
                "type": "nested",
                "properties": {
                    "type_info": {"type": "text"},
                    "op_type": {"type": "text"},
                    "file_name": {"type": "text"},
                    "file_ext": {"type": "text"},
                    "process_id": {"type": "text"},
                    "time_stamp": {"type": "text"}
                }
            }
         }
      }
    }
    

    要插入的文档格式:

    {
      "event_info" : {
          "type_info": "INFO", 
          "op_type": "WRITE", 
          "file_name": "0.txt", 
          "file_ext": ".txt", 
          "process_id": "1234", 
          "time_stamp": "2022-10-17 05:23:06.8620427 +0000 UTC"
       }
    }
    

    如果使用bulk,您可以将文档放入:

    {"index": {"_index": "your_index"}}
    {"event_info": {"type_info": "INFO", "op_type": "WRITE", "file_name": "0.txt","file_ext": ".txt", "process_id": "1234", "time_stamp": "2022-10-17 05:23:06.8620427 +0000 UTC"}}
    

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多