Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to post data to jobs via x-pack machine learning api #959

Closed
rbochz28 opened this issue May 20, 2019 · 1 comment · Fixed by #962
Closed

Unable to post data to jobs via x-pack machine learning api #959

rbochz28 opened this issue May 20, 2019 · 1 comment · Fixed by #962

Comments

@rbochz28
Copy link

I am unable to post data to machine learning jobs via the MlClient post_data method. There seems to be a problem with getting the data:

Here is a json doc example named file_name.json:

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

Here is some example code used to post the 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()

Here is the error I am getting when sending json docs:

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'
@rbochz28
Copy link
Author

If I remove body=self._bulk_body(body) from the post_data method in ml.py and replace with body=body I was able to send json docs in the above format. Should the _bulk_body be called in the post_data method in the MlClient?

fxdgear added a commit that referenced this issue May 22, 2019
Need to access the _bulk_body method from the client object

closes: #959
fxdgear added a commit that referenced this issue May 23, 2019
* ml client has not method _bulk_body

Need to access the _bulk_body method from the client object

closes: #959

* update changelog too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant