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

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

问题描述

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

这是列表(虚拟)

  [" labels:imagenet_labels.txt" ;,模型:efficiencynet-edgetpu-S_quant_edgetpu.tflite","图片:worm.jpg" ;,"Time(ms):23.1",时间(毫秒):5.7",推断:开瓶器,瓶螺钉","分数:0.03125" ;,"TPU_temp(℃):57.05"," labels:imagenet_labels.txt" ;,模型:efficiencynet-edgetpu-M_quant_edgetpu.tflite","图片:worm.jpg" ;,"Time(ms):29.3",时间(毫秒):10.8",推论:蜻蜓,织补针,恶魔的织补针,缝纫针,喂蛇器,蛇医生,蚊子鹰、,子鹰",<分数:0.09375" ;,"TPU_temp(℃):56.8"," labels:imagenet_labels.txt" ;,模型:efficiencynet-edgetpu-L_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):45.6","Time(ms):31.0&",推断:拨片,拨子,拨子","分数:0.09766" ;,"TPU_temp(℃):57.55"," labels:imagenet_labels.txt" ;,模型:inception_v3_299_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):68.8",时间(毫秒):51.3",<推论:小环,小环蝴蝶> ;,"分数:0.48047" ;,"TPU_temp(℃):57.3"," labels:imagenet_labels.txt" ;,模型:inception_v4_299_quant_edgetpu.tflite","图片:worm.jpg" ;,"Time(ms):121.8",时间(毫秒):101.2",推断:海军上将",<分数:0.59375" ;,"TPU_temp(℃):57.05"," labels:imagenet_labels.txt" ;,模型:inception_v2_224_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):34.3",时间(毫秒):16.6",推断:lycaenid,lycaenid蝴蝶","分数:0.41406" ;,"TPU_temp(℃):57.3"," labels:imagenet_labels.txt" ;,模型:mobilenet_v2_1.0_224_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):14.4",时间(毫秒):3.3",推论:棱皮龟,棱皮龟,革龟,Dermochelys coriacea","分数:0.36328" ;,"TPU_temp(℃):57.3"," labels:imagenet_labels.txt" ;,型号:mobilenet_v1_1.0_224_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):14.5",时间(毫秒):3.0",推断:领结,领结,领结","分数:0.33984" ;,"TPU_temp(℃):57.3"," labels:imagenet_labels.txt" ;,模型:inception_v1_224_quant_edgetpu.tflite","图片:worm.jpg" ;,时间(毫秒):21.2",时间(毫秒):3.6",推断:拨片,拨子,拨子",分数:0.17578","TPU_temp(℃):57.3",] 

这就是脚本

  import elasticsearch6从elasticsearch6导入Elasticsearch,助手导入日期时间汇入ES_DEV_HOST =" http://localhost:9200/"INDEX_NAME ="coral_ia";#索引名称DOC_TYPE ='coral_edge'#数据类型##这是列表dummy = ['labels:imagenet_labels.txt \ n','\ n','Model:efficiencynet-edgetpu-S_quant_edgetpu.tflite \ n','\ n','Image:insect.jpg \ n','\ n','*在Edge TPU上的第一个推断很慢,因为它包括将模型加载到Edge TPU内存中* \ n','Time(ms):23.1 \ n','Time(ms):5.7 \ n','\ n','\ n','推断:开瓶器,瓶螺钉\ n','得分:0.03125 \ n','\ n','TPU_temp(°C):57.05 \ n','##################################### \ n','\ n','labels:imagenet_labels.txt \ n','\ n','模型:efficiencynet-edgetpu-M_quant_edgetpu.tflite \ n','\ n','图片:worm.jpg \ n','\ n','*关于Edge TPU的第一个推论是速度较慢,因为它包括将模型加载到Edge TPU内存中* \ n','时间(毫秒):29.3 \ n','时间(毫秒):10.8 \ n','\ n','\ n',推论:蜻蜓,织补针,恶魔的织补针,缝纫针,蛇喂食器,蛇医生,蚊子鹰、,子鹰\ n,'得分:0.09375 \ n','\ n','TPU_temp(°C):56.8\ n','################################### \ n','\ n','labels:imagenet_labels.txt \ n','\ n','型号:efficiencynet-edgetpu-L_quant_edgetpu.tflite \ n','\ n','图片:worm.jpg \ n','\ n','*第一个Edge TPU的推理速度很慢,因为它包括将模型加载到Edge TPU内存中* \ n','Time(ms):45.6 \ n','Time(ms):31.0 \ n','\ n','\n','推断:pick,plectrum,plectron \ n','得分:0.09766 \ n','\ n','TPU_temp(°C):57.55 \ n','###################################### \ n','\ n','labels:imagenet_labels.txt \ n','\ n','Model:inception_v3_299_quant_edgetpu.tflite \ n','\ n','Image:insect.jpg \ n','\ n','*在Edge TPU上的第一个推断很慢,因为它包括将模型加载到Edge中TPU内存* \ n','时间(毫秒):68.8 \ n','时间(毫秒):51.3 \ n','\ n','\ n','推断:小环,小环蝴蝶\ n','得分:0.48047 \ n','\ n','TPU_temp(°C):57.3 \ n','##################################### \ n','\ n','标签:imagenet_labels.txt \ n','\ n','型号:inception_v4_299_quant_edgetpu.tflite \ n','\ n','图片:worm.jpg \ n','\ n','* Edge上的第一个推论TPU速度很慢,因为它包括将模型加载到Edge TPU内存中* \ n','时间(ms):121.8 \ n','时间(ms):101.2 \ n','\ n','\ n','推论:海军上将\ n','得分:0.59375 \ n','\ n','TPU_temp(°C):57.05 \ n','####################################### \ n','\ n','标签:imagenet_labels.txt \ n','\ n','型号:inception_v2_224_quant_edgetpu.tflite \ n','\ n','Image:insect.jpg \ n','\ n','*在Edge TPU上的第一个推断很慢,因为它包括将模型加载到Edge TPU内存中* \ n','时间(毫秒):34.3 \ n','时间(毫秒):16.6 \ n','\ n','\ n','推断:lycaenid,lycaenid蝴蝶\ n','得分:0.41406 \ n','\ n','TPU_temp(°C):57.3 \ n','###################################### \ n','\ n','标签:imagenet_labels.txt \ n','\ n','型号:mobilenet_v2_1.0_224_quant_edgetpu.tflite \ n','\ n','图片:insect.jpg \ n','\ n','*在Edge TPU上的第一个推断很慢,因为它包括将模型加载到Edge TPU内存中* \ n','Time(ms):14.4 \ n','Time(毫秒):3.3 \ n','\ n','\ n','推断:棱皮龟,棱皮龟,革龟,Dermochelys coriacea \ n','得分:0.36328 \ n','\ n','TPU_temp(°C):57.3 \ n','#################################### \ n','\ n','labels:imagenet_labels.txt \ n','\ n','Model:mobilenet_v1_1.0_224_quant_edgetpu.tflite \ n','\ n','Image:insect.jpg \ n','\ n','*在Edge TPU上的第一个推论很慢,因为它包括将模型加载到Edge中TPU内存* \ n','时间(毫秒):14.5 \ n','时间(毫秒):3.0 \ n','\ n','\ n','推断:领结,领结,领结\ n','得分:0.33984 \ n','\ n','TPU_temp(°C):57.3 \ n','##################################### \ n','\ n','标签:imagenet_labels.txt \ n','\ n','型号:inception_v1_224_quant_edgetpu.tflite \ n','\ n','图像:insect.jpg \ n','\ n','*在Edge TPU上的第一个推断很慢,因为它包括将模型加载到Edge TPU内存中* \ n','Time(ms):21.2 \ n','时间(毫秒):3.6 \ n','\ n','\ n','推断:拨片,拨子,拨子\ n','分数:0.17578 \ n','\n','TPU_temp(°C):57.3 \ n','##################################### \ n','\ n']#这是清除数据并过滤一些值regex = re.compile(r'(\ w +)\((.+)\):\ s(.*)|(\ w +:)\ s(.*)')match_regex = list(过滤器(regex.match,虚拟))match = [line.strip('\ n')for match_regex中的行]打印(匹配列表",匹配,"\ n")##将列表转换为字典列表组= [{}]符合条件的线:键,值= line.split(:",1)如果键==标签":如果群组[-1]:groups.append({})组[-1] [键] =值"通过服务器的IP初始化Elasticsearch"def initialize_elasticsearch():n = 0而n <== 10时:尝试:es = Elasticsearch(ES_DEV_HOST)print(正在初始化Elasticsearch ...")返回es除了elasticsearch6.exceptions.ConnectionTimeout如e:### elasticsearch打印(e)n + = 1继续引发异常"如果尚未在Elasticsearch中创建索引,请在其中创建索引"def initialize_mapping(es):mapping_classification = {'特性': {'timestamp':{'type':'date'},#'type':{'type':'keyword'},< ---我已经删除了'labels':{'type':'keyword'},'型号':{'类型':'关键字'},'图片':{'类型':'关键字'},'Time(ms)':{'type':'short'},'推论':{'类型':'文本'},'分数':{'type':'short'},'TPU_temp(°C)':{'type':'short'}}}print(正在初始化映射...")如果不是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,'timestamp':str(datetime.datetime.utcnow().strftime(%Y-%m-%d"'T'%H:%M:%S")),'_type':DOC_TYPE,'_source':群组}屈服动作打印(正在生成操作...")#print("actions:",actions)#print(type(actions),"\ n")def main():es = initialize_elasticsearch()initialize_mapping(es)尝试:res = helpers.bulk(客户= es,索引= INDEX_NAME,操作= generate_actions())打印("\ nhelpers.bulk()响应:",res)打印("RESPONSE TYPE:",类型(res))例外为err:打印("\ nhelpers.bulk()错误:",错误)如果__name__ =="__main__":主要的() 

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

  regex = re.compile(r'(\ w +)\((.+)\):\ s(.*)|(\ w +:)\ s(.*)')match_regex = list(过滤器(regex.match,虚拟))match = [line.rstrip('\ n')for match_regex中的行] #quita los saltos de linea#print(匹配列表",匹配,"\ n")features_wanted ='ModelImageTime(ms)InferenceScoreTPU_temp(°C)'match_out = {i.replace('','').split(':')[0]:i.replace('','').split(':')[1].replace('','').split(':')[0] in features_wanted} 

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

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

这就是映射

当我想要查看数据时会出现这种情况

已对数据进行索引...

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

我修改了 generate_actions

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

解决方案

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

因此,您需要像这样重写您的 generate_actions fn:

  def generate_actions():返回 [{'timestamp':str(datetime.datetime.utcnow().strftime(%Y-%m-%d"'T'%H:%M:%S")),'_index':INDEX_NAME,'_type':DOC_TYPE,'_source':doc}分组文档中的文档]#< -----请注意此处的表单循环.`_source`需求#成为文档,而不是整个组列表打印(正在生成操作...") 

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

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

#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('\n') for line in match_regex]   
print("match list", match, "\n")


##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), "\n")



def main():
    es=initialize_elasticsearch()
    initialize_mapping(es)  
    
    try:
        res=helpers.bulk(client=es, index = INDEX_NAME, actions = generate_actions())
        print ("\nhelpers.bulk() RESPONSE:", res)
        print ("RESPONSE TYPE:", type(res))
        
    except Exception as err:
        print("\nhelpers.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('\n') for line in match_regex]   #quita los saltos de linea
#print("match list", match, "\n")


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天全站免登陆