简体   繁体   English

如何将数据发布到作业api elasticsearch

[英]How to send data post data to jobs api elasticsearch

I'm trying to post data to a machine learning api using elasticsearch. 我正在尝试使用elasticsearch将数据发布到机器学习api。 What format does the json docs need to be in? json docs需要采用什么格式?

I've attempted to send data with json docs separated by newline in a txt file. 我试图在txt文件中使用换行符分隔的json docs发送数据。 I've also tried converting back and forth to json using dump and load to no avail. 我也尝试使用转储和加载来回转换为json无济于事。 The documentation states that the documents can be separated by whitespace, but no matter what I try it won't accept them. 文档说明文档可以用空格分隔,但无论我尝试什么,它都不会接受它们。

https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html

Here is an example of a json doc saved as file_name.json: 以下是保存为file_name.json的json doc的示例:

[{"myid": "id1", "client": "client1", "submit_date": 1514764857},
 {"my_id": "id2", "client": "client_2", "submit_date": 1514764857}]

Here is the basic code needed to post data: 以下是发布数据所需的基本代码:

from elasticsearch import Elasticsearch
from elasticsearch.client.xpack import MlClient

es = elastic_connection()
es_ml = MlClient(es)

def post_training_data(directory='Training Data', file_name='file_name.json'):
        with open(os.path.join(directory, file_name), mode='r') as train_file:
            train_data = json.load(train_file)
            es_ml.post_data(job_id=job_id, body=train_data)

post_training_data()

This is the specific error I am getting with this: 这是我得到的具体错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "..\train_model.py", line 218, in post_training_data
    self.es_ml.post_data(job_id=self.job_id, body=train_data)
  File "..\inc_anamoly\lib\site-packages\elasticsearch\client\utils.py", line 76, in _wrapped
    return func(*args, params=params, **kwargs)
  File "..\inc_anamoly\lib\site-packages\elasticsearch\client\xpack\ml.py", line 81, in post_data
    body=self._bulk_body(body))
AttributeError: 'MlClient' object has no attribute '_bulk_body'

This turns out to be a bug. 事实证明这是一个错误。 Issue reported. 问题报道。

https://github.com/elastic/elasticsearch-py/issues/959 https://github.com/elastic/elasticsearch-py/issues/959

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM