'压缩器检测只能在某些 xcontent 字节或压缩的 xcontent 字节上调用"索引字典列表时出错 [英] 'Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes" error when indexing a list of dictionaries

查看:31
本文介绍了'压缩器检测只能在某些 xcontent 字节或压缩的 xcontent 字节上调用"索引字典列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与另一个问题有关:

这是清单(虚拟)

<预><代码>[标签:imagenet_labels.txt",模型:高效net-edgetpu-S_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):23.1",时间(毫秒):5.7",推断:开瓶器,瓶螺丝",得分:0.03125",TPU_temp(°C):57.05",标签:imagenet_labels.txt",模型:高效net-edgetpu-M_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):29.3",时间(毫秒):10.8",推断:蜻蜓、织补针、魔鬼的织补针、缝纫针、喂蛇器、蛇医、蚊鹰、斯基特鹰",分数:0.09375",TPU_temp(°C):56.8",标签:imagenet_labels.txt",模型:高效net-edgetpu-L_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):45.6",时间(毫秒):31.0",推理:拨片,拨片,拨片",得分:0.09766",TPU_temp(°C):57.55",标签:imagenet_labels.txt",模型:inception_v3_299_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):68.8",时间(毫秒):51.3",推断:小环,小环蝴蝶",得分:0.48047",TPU_temp(°C):57.3",标签:imagenet_labels.txt",模型:inception_v4_299_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):121.8",时间(毫秒):101.2",推理:海军上将",得分:0.59375",TPU_temp(°C):57.05",标签:imagenet_labels.txt",模型:inception_v2_224_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):34.3",时间(毫秒):16.6",推断:lycaenid,lycaenid蝴蝶",得分:0.41406",TPU_temp(°C):57.3",标签:imagenet_labels.txt",型号:mobilenet_v2_1.0_224_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):14.4",时间(毫秒):3.3",推断:棱皮龟,棱皮龟,革甲龟,Dermochelys coriacea",得分:0.36328",TPU_temp(°C):57.3",标签:imagenet_labels.txt",型号:mobilenet_v1_1.0_224_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):14.5",时间(毫秒):3.0",推理:领结,领结,领结",得分:0.33984",TPU_temp(°C):57.3",标签:imagenet_labels.txt",模型:inception_v1_224_quant_edgetpu.tflite","图片:昆虫.jpg ",时间(毫秒):21.2",时间(毫秒):3.6",推理:拨片,拨片,拨片",得分:0.17578",TPU_temp(°C):57.3",]

这是脚本

import elasticsearch6from elasticsearch6 导入 Elasticsearch, helpers导入日期时间进口重新ES_DEV_HOST = "http://localhost:9200/";INDEX_NAME = "coral_ia";#索引名称DOC_TYPE = 'coral_edge' #数据类型##这是清单dummy = ['labels: imagenet_labels.txt 
', '
', '模型:高效net-edgetpu-S_quant_edgetpu.tflite 
', '
', '图片:昆虫.jpg 
', '
', '*Edge TPU 上的第一次推理很慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 23.1
', 'Time(ms): 5.7
', '
', '
', '推理:开瓶器,瓶螺丝
', '分数:0.03125 
', '
', 'TPU_temp(°C): 57.05
', '###################################
', '
', 'labels: imagenet_labels.txt 
', '
', '模型:efficientnet-edgetpu-M_quant_edgetpu.tflite 
', '
', '图片:昆虫.jpg 
', '
', '*Edge TPU上的第一个推断是慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 29.3
', 'Time(ms): 10.8
', '
', '
', "推论:蜻蜓、织补针、魔鬼织补针、缝纫针、喂蛇器、蛇医、蚊鹰、斯基特鹰
", 'Score: 0.09375 
', '
', 'TPU_temp(°C): 56.8
', '###################################
', '
', '标签:imagenet_labels.txt 
', '
', '模型:efficientnet-edgetpu-L_quant_edgetpu.tflite 
', '
', '图片:昆虫.jpg 
', '
', '*第一个Edge TPU 上的推理很慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 45.6
', 'Time(ms): 31.0
', '
', '
', 'Inference: pick, plectrum, plectron
', 'Score: 0.09766 
', '
', 'TPU_temp(°C): 57.55
', '#################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v3_299_quant_edgetpu.tflite 
', '
', 'Image:昆虫.jpg 
', '
', '*Edge TPU上的第一次推理很慢,因为它包括将模型加载到Edge中TPU 内存*
', 'Time(ms): 68.8
', 'Time(ms): 51.3
', '
', '
', 'Inference: ringlet, ringlet蝴蝶
','分数:0.48047
'、'
'、'TPU_temp(°C):57.3
'、'################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v4_299_quant_edgetpu.tflite 
', '
', '图片:昆虫.jpg 
', '
', '*Edge 上的第一次推断TPU 很慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 121.8
', 'Time(ms): 101.2
', '
', '
','推理:海军上将
', 'Score: 0.59375 
', '
', 'TPU_temp(°C): 57.05
', '#################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v2_224_quant_edgetpu.tflite 
', '
', 'Image: infant.jpg 
', '
', '*Edge TPU 上的第一次推理很慢,因为它包括将模型加载到 Edge TPU 内存中*
','Time(ms): 34.3
', 'Time(ms): 16.6
', '
', '
', 'Inference: lycaenid, lycaenid蝴蝶
', 'Score: 0.41406 
', '
', 'TPU_temp(°C): 57.3
', '################################## 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite 
', '
', '图片:昆虫.jpg 
', '
', '*Edge TPU 上的第一次推理很慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 14.4
', 'Time(ms): 3.3
', '
', '
', '推理:棱皮龟乌龟,棱皮龟,革龟,Dermochelys coriacea
', 'Score: 0.36328 
', '
', 'TPU_temp(°C): 57.3
', '####################################
', '
', 'labels: imagenet_labels.txt 
', '
','Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite 
', '
', 'Image: Incent.jpg 
', '
', '*Edge TPU 上的第一次推理很慢,因为它包括将模型加载到 EdgeTPU 内存*
', 'Time(ms): 14.5
', 'Time(ms): 3.0
', '
', '
', 'Inference: bow tie, bow-tie, bowtie
', 'Score: 0.33984 
', '
', 'TPU_temp(°C): 57.3
', '####################################
', '
', 'labels: imagenet_labels.txt 
', '
', '模型:inception_v1_224_quant_edgetpu.tflite 
', '
', '图像:昆虫.jpg 
', '
', '*Edge TPU 上的第一次推理很慢,因为它包括将模型加载到 Edge TPU 内存中*
', 'Time(ms): 21.2
', 'Time(ms): 3.6
', '
', '
', 'Inference: pick, plectrum, plectron
', 'Score: 0.17578 
', '
', 'TPU_temp(°C): 57.3
', '################################### 
', '
']#这是清理数据和过滤一些值regex = re.compile(r'(w+)((.+)):s(.*)|(w+:)s(.*)')match_regex = list(filter(regex.match, dummy))match = [line.strip('
') for line in match_regex]打印(匹配列表",匹配,
")##将列表转换为字典列表组 = [{}]对于匹配线:key, value = line.split(": ", 1)如果键==标签":如果组[-1]:组.追加({})组[-1][键] = 值"通过服务器的 IP 初始化 Elasticsearch'"def initialize_elasticsearch():n = 0当 n <= 10 时:尝试:es = Elasticsearch(ES_DEV_HOST)打印(初始化 Elasticsearch...")返回 es除了 elasticsearch6.exceptions.ConnectionTimeout 为 e: ###elasticsearch打印(e)n += 1继续引发异常"如果尚未在 Elasticsearch 中创建索引,则在该索引中创建索引"def initialize_mapping(es):mapping_classification = {'特性': {'时间戳':{'类型':'日期'},#'type': {'type':'keyword'}, <--- 我已经删除了'标签':{'类型':'关键字'},'模型':{'类型':'关键字'},'图片':{'类型':'关键字'},'时间(毫秒)':{'类型':'短'},'推理':{'类型':'文本'},'Score': {'type': 'short'},'TPU_temp(°C)': {'type': 'short'}}}打印(初始化映射...")如果不是 es.indices.exists(INDEX_NAME):es.indices.create(INDEX_NAME)es.indices.put_mapping(body=mapping_classification, doc_type=DOC_TYPE, index=INDEX_NAME)def generate_actions():动作 = {'_index': INDEX_NAME,'时间戳': str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),'_type':DOC_TYPE,'_source':组}屈服行动打印(生成动作...")#print(动作:",动作)#print(type(actions), "
")定义主():es=initialize_elasticsearch()initialize_mapping(es)尝试:res=helpers.bulk(client=es, index = INDEX_NAME, actions = generate_actions())打印(
helpers.bulk()响应:",res)打印(响应类型:",类型(res))除了作为错误的异常:打印(
helpers.bulk()错误:",错误)如果 __name__ == __main__":主要的()

这是仅使用 1 个字典进行测试时的代码

regex = re.compile(r'(w+)((.+)):s(.*)|(w+:)s(.*)')match_regex = list(filter(regex.match, dummy))match = [line.rstrip('
') for line in match_regex] #quita los saltos de linea#print(匹配列表",匹配,
")features_wanted='ModelImageTime(ms)InferenceScoreTPU_temp(°C)'match_out = {i.replace(' ','').split(':')[0]:i.replace(' ','').split(':')[1] for i in match if i.replace(' ','').split(':')[0] in features_wanted}

-------------------编辑-------------------------

没有错误,但是正在生成操作..."未打印.

这是地图

当我想查看数据是否已编入索引时会出现这种情况

似乎数据已编入索引...

----------------------编辑----------------------

我修改了generate_actions

def generate_actions():返回[{'_index': INDEX_NAME,'_type':DOC_TYPE,'_来源': {任何":文档,"@timestamp": str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),}}对于组中的文档]

解决方案

这个有点神秘的错误消息告诉您,您需要将单个对象而不是一组对象传递给批量帮助程序.

所以你需要像这样重写你的generate_actions fn:

def generate_actions():返回 [{'时间戳': str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),'_index': INDEX_NAME,'_type':DOC_TYPE,'_source':文档} for doc in groups] # <----- 注意这里的表单循环.`_source` 需要# 成为文档,而不是整个组列表打印(生成动作...")

此外,我建议您在构建 groups 时从键值对中删除尾随空格:

groups[-1][key] = value.strip()

This question is related to this other one: How can I read data from a list and index specific values into Elasticsearch, using python?

I have written a script to read a list ("dummy") and index it into Elasticsearch. I converted the list into a list of dictionaries and used the "Bulk" API to index it into Elasticsearch. The script used to work (check the attached link to the related question). But it is no longer working after adding "timestamp" and the function "initialize_elasticsearch".

So, what is wrong? Should I be using JSON instead of the list of dictionaries?

I have also tried using only 1 dictionary of the list. In that case there is no error but nothing gets indexed.

THIS IS THE ERROR

THIS IS THE LIST (dummy)

[
    "labels: imagenet_labels.txt ",
    "Model: efficientnet-edgetpu-S_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 23.1",
    "Time(ms): 5.7",
    "Inference: corkscrew, bottle screw",
    "Score: 0.03125 ",
    "TPU_temp(°C): 57.05",
    "labels: imagenet_labels.txt ",
    "Model: efficientnet-edgetpu-M_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 29.3",
    "Time(ms): 10.8",
    "Inference: dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
    "Score: 0.09375 ",
    "TPU_temp(°C): 56.8",
    "labels: imagenet_labels.txt ",
    "Model: efficientnet-edgetpu-L_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 45.6",
    "Time(ms): 31.0",
    "Inference: pick, plectrum, plectron",
    "Score: 0.09766 ",
    "TPU_temp(°C): 57.55",
    "labels: imagenet_labels.txt ",
    "Model: inception_v3_299_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 68.8",
    "Time(ms): 51.3",
    "Inference: ringlet, ringlet butterfly",
    "Score: 0.48047 ",
    "TPU_temp(°C): 57.3",
    "labels: imagenet_labels.txt ",
    "Model: inception_v4_299_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 121.8",
    "Time(ms): 101.2",
    "Inference: admiral",
    "Score: 0.59375 ",
    "TPU_temp(°C): 57.05",
    "labels: imagenet_labels.txt ",
    "Model: inception_v2_224_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 34.3",
    "Time(ms): 16.6",
    "Inference: lycaenid, lycaenid butterfly",
    "Score: 0.41406 ",
    "TPU_temp(°C): 57.3",
    "labels: imagenet_labels.txt ",
    "Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 14.4",
    "Time(ms): 3.3",
    "Inference: leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
    "Score: 0.36328 ",
    "TPU_temp(°C): 57.3",
    "labels: imagenet_labels.txt ",
    "Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 14.5",
    "Time(ms): 3.0",
    "Inference: bow tie, bow-tie, bowtie",
    "Score: 0.33984 ",
    "TPU_temp(°C): 57.3",
    "labels: imagenet_labels.txt ",
    "Model: inception_v1_224_quant_edgetpu.tflite ",
    "Image: insect.jpg ",
    "Time(ms): 21.2",
    "Time(ms): 3.6",
    "Inference: pick, plectrum, plectron",
    "Score: 0.17578 ",
    "TPU_temp(°C): 57.3",
]

THIS IS THE SCRIPT

import elasticsearch6  
from elasticsearch6 import Elasticsearch, helpers
import datetime
import re



ES_DEV_HOST = "http://localhost:9200/"
INDEX_NAME = "coral_ia" #name of index
DOC_TYPE = 'coral_edge'  #type of data



##This is the list
dummy = ['labels: imagenet_labels.txt 
', '
', 'Model: efficientnet-edgetpu-S_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 23.1
', 'Time(ms): 5.7
', '
', '
', 'Inference: corkscrew, bottle screw
', 'Score: 0.03125 
', '
', 'TPU_temp(°C): 57.05
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: efficientnet-edgetpu-M_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 29.3
', 'Time(ms): 10.8
', '
', '
', "Inference: dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk
", 'Score: 0.09375 
', '
', 'TPU_temp(°C): 56.8
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: efficientnet-edgetpu-L_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 45.6
', 'Time(ms): 31.0
', '
', '
', 'Inference: pick, plectrum, plectron
', 'Score: 0.09766 
', '
', 'TPU_temp(°C): 57.55
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v3_299_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 68.8
', 'Time(ms): 51.3
', '
', '
', 'Inference: ringlet, ringlet butterfly
', 'Score: 0.48047 
', '
', 'TPU_temp(°C): 57.3
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v4_299_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 121.8
', 'Time(ms): 101.2
', '
', '
', 'Inference: admiral
', 'Score: 0.59375 
', '
', 'TPU_temp(°C): 57.05
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v2_224_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 34.3
', 'Time(ms): 16.6
', '
', '
', 'Inference: lycaenid, lycaenid butterfly
', 'Score: 0.41406 
', '
', 'TPU_temp(°C): 57.3
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 14.4
', 'Time(ms): 3.3
', '
', '
', 'Inference: leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea
', 'Score: 0.36328 
', '
', 'TPU_temp(°C): 57.3
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 14.5
', 'Time(ms): 3.0
', '
', '
', 'Inference: bow tie, bow-tie, bowtie
', 'Score: 0.33984 
', '
', 'TPU_temp(°C): 57.3
', '##################################### 
', '
', 'labels: imagenet_labels.txt 
', '
', 'Model: inception_v1_224_quant_edgetpu.tflite 
', '
', 'Image: insect.jpg 
', '
', '*The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory*
', 'Time(ms): 21.2
', 'Time(ms): 3.6
', '
', '
', 'Inference: pick, plectrum, plectron
', 'Score: 0.17578 
', '
', 'TPU_temp(°C): 57.3
', '##################################### 
', '
']

#This is to clean data and filter some values
regex = re.compile(r'(w+)((.+)):s(.*)|(w+:)s(.*)')
match_regex = list(filter(regex.match, dummy))
match = [line.strip('
') for line in match_regex]   
print("match list", match, "
")


##Converts the list into a list of dictionaries
groups = [{}]

for line in match:
    key, value = line.split(": ", 1)
    if key == "labels":
        if groups[-1]:
            groups.append({})
    groups[-1][key] = value



"""
Initialize Elasticsearch by server's IP'
"""
def initialize_elasticsearch():
    n = 0
    while n <= 10:
        try:
            es = Elasticsearch(ES_DEV_HOST)
            print("Initializing Elasticsearch...")
            return es
        except elasticsearch6.exceptions.ConnectionTimeout as e:  ###elasticsearch
            print(e)
            n += 1
            continue
    raise Exception



"""
Create an index in Elasticsearch if one isn't already there
"""
def initialize_mapping(es):
    mapping_classification = {
        'properties': {
            'timestamp': {'type': 'date'},
            #'type': {'type':'keyword'}, <--- I have removed this 
            'labels': {'type': 'keyword'},
            'Model': {'type': 'keyword'},
            'Image': {'type': 'keyword'},
            'Time(ms)': {'type': 'short'},
            'Inference': {'type': 'text'},
            'Score': {'type': 'short'},
            'TPU_temp(°C)': {'type': 'short'}
        }
    }
    print("Initializing the mapping ...")  
    if not es.indices.exists(INDEX_NAME):
        es.indices.create(INDEX_NAME)
        es.indices.put_mapping(body=mapping_classification, doc_type=DOC_TYPE, index=INDEX_NAME)
        



def generate_actions():
    actions = {
        '_index': INDEX_NAME,
        'timestamp': str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),
        '_type': DOC_TYPE,
        '_source': groups
        }

    yield actions
    print("Generating actions ...")
    #print("actions:", actions)
    #print(type(actions), "
")



def main():
    es=initialize_elasticsearch()
    initialize_mapping(es)  
    
    try:
        res=helpers.bulk(client=es, index = INDEX_NAME, actions = generate_actions())
        print ("
helpers.bulk() RESPONSE:", res)
        print ("RESPONSE TYPE:", type(res))
        
    except Exception as err:
        print("
helpers.bulk() ERROR:", err)


if __name__ == "__main__":
    main()

THIS IS THE CODE WHEN TESTING WITH ONLY 1 DICTIONARY

regex = re.compile(r'(w+)((.+)):s(.*)|(w+:)s(.*)')
match_regex = list(filter(regex.match, dummy))
match = [line.rstrip('
') for line in match_regex]   #quita los saltos de linea
#print("match list", match, "
")


features_wanted='ModelImageTime(ms)InferenceScoreTPU_temp(°C)'
match_out = {i.replace(' ','').split(':')[0]:i.replace(' ','').split(':')[1] for i in match if i.replace(' ','').split(':')[0] in features_wanted}

-------------------EDIT-------------------------

No errors, but "Generating actions ..." is not being printed.

THIS IS THE MAPPING

THIS APPEARS WHEN I WANT TO SEE IF THE DATA WAS INDEXED

IT SEEMS THE DATA HAS BEEN INDEXED...

----------------------EDIT-----------------------

I modified the generate_actions

def generate_actions():
    return[{
        '_index': INDEX_NAME,
        '_type': DOC_TYPE,
        '_source': {
            "any": doc,
            "@timestamp": str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),}
        }
        for doc in groups]

解决方案

This somewhat cryptic error msg is telling you that you need to pass single objects instead of an array of them to the bulk helpers.

So you need to rewrite your generate_actions fn like so:

def generate_actions():
    return [{
        'timestamp': str(datetime.datetime.utcnow().strftime("%Y-%m-%d"'T'"%H:%M:%S")),
        '_index': INDEX_NAME,
        '_type': DOC_TYPE,
        '_source': doc
    } for doc in groups]      # <----- note the form loop here. `_source` needs
                              # to be the doc, not the whole groups list

    print("Generating actions ...")

Also, I'd recommend to remove the trailing whitespace from your key-value pairs when you construct the groups:

groups[-1][key] = value.strip()

这篇关于'压缩器检测只能在某些 xcontent 字节或压缩的 xcontent 字节上调用"索引字典列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆