Get specific template from elasticsearch via python - python

I'm trying to get a template from AWS OpenSearch via python.
Now I know that from the Kibana it's:
GET _template/<template_name>
and from python, I have the function "search_template()" but it's forcing me to use the "body" parameter which I actually don't use in the kibana.
Does someone know how I can get the template?

What you're looking for is probably get_template(template_name)

Related

Creating a sortable table (with React.js) that was produced using Flask and Bootstrap

I've got a table that I've created using Flask by getting data from an API and later compiling it into a table with bootstrap as a front end. I want to make the headers clickable in order to sort them, I've heard that React.js might be a good option for this, is there anyway for me to use React directly with my table without rewriting the entire app in javascript?
Possibly! If you can install react then you should be able to use a library such as the react-collapsing-table. You would need to install it with npm then you should be able to import/require it on your page and just do
<ReactCollapsingTable rows={data} columns={columns} />
Hope that helps :)
I implemented a react-bootstrap-table2 frontend with a flask backend here: http://thomaxxl.pythonanywhere.com/ja/index.html#/books (no sorting implemented there but it is possible by using the appropriate react-bootstrap-table syntax: https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/basic-sort.html )
You can implement sorting in the backend or the frontend.
To implement it in the backend, your api must support sorting parameters (eg. in the query string: ?sort=title,id )
To implement sorting in the frontend you must fetch all your data which is not feasible for large tables
Other things you may want to consider are pagination, filtering and search.

Show Server details via Python OpenStack API using the nova client

I am trying to convert my BASH script to Python and am having difficulties in finding the equivalent code for openstack server show or openstack server list --long. I would like to know what host is my server currently located and use this information for a check before migrating it to another host.
Looking through the latest novaclient documentation and its servers module, I have found two potential commands that I was hoping would accomplish the task, but does not do so:
list(detailed=True)
Gets a list servers
detailed=True should return detailed server info (optional).
This returns a regular list of servers with their names.
get(server)
Get a server
This returns only the name of the server.
I have been researching for the past two days, and I could not find the same / similar problem here in stack overflow so I have decided to ask and I am hoping that someone can help me with this.
Either list or get should be fine here.
As an example get would be used like this.
instance = nova_client.servers.get('my-server')
print(instance.name)
print(instance.addresses)
print(instance.status)
Or using list.
for instance in nova_client.servers.list():
print(instance.name)
print(instance.addresses)
print(instance.status)
If you want an easy way of understanding the type of data you can get, you can simply use the Python inbuilt dir.
instance = nova_client.servers.get('my-server')
print(dir(instance))
'my-server' needs to be the id as in instance.id, the name of the server is not valid.
I cant yet comment, so i wrote an answer.

Ignoring a ProtoRPC message field via Cloud Endpoints

I've been working on an AppEngine-based project and I wanted to know if it's possible to ignore a ProtoRPC message field.
With the Java SDK, you can use #ApiResourceProperty to ignore a property (this means it's not contained within the response returned to the browser). However, I have not come across a way of doing this using the Python SDK.
Is there anything like this in the Python SDK?
Thanks, Adil
Nope, unfortunately not (at least not to my knowledge).
Two possible solutions depending on your use-case.
Set field values to None before returning the message in your method. That way they will be skipped/not included in the JSON response.
If your messages are hooked up to datastore models you can use the endpoints-proto-datastore library which allows you to use your ndb models directly in your API methods. Additionally it allows for request_fields and response_fields parameters in the method decorator which will limit the request or response to the specified subset of message/model fields. (internally it creates the necessary message classes for you)

Setting up a Python ViewServer for CouchDB

I am trying to get up to speed with CouchDB. As a relatively new user on Python, I am trying to set up a view-server so that I can pass on python functions to couchdb.design.ViewDefinitions function. As I understand, ViewDefinitions take javascript code to execute map/reduce function.
Here is what I struggle to understand - I am well aware that this might be a basic question. According to wiki (http://wiki.apache.org/couchdb/View_server):
To register query servers with CouchDB, add a line for each server to local.ini. The basic syntax is:
'[query_servers] python=/usr/bin/couchpy'
How do I access local.ini file? I am an 10.6.8 Mac user. Thanks!
Update: Thank you Kxepal. It seems I was able to create the design/view on Futon in Python. Alternatively, I figured that python viewserver can be created as follows:
curl -X PUT http://[localhost]/_config/query_servers/python '"/path/to/couchpy"'
However, I still cannot execute the python script. Running the view on Couch results in following:
'Error: An error occurred accessing the view no response'
I would appreciate if somebody can point in the right direction. Thanks!
I encountered the same "Error: An error occurred accessing the view no response" problem, and it turned out to be a bug in my python code. Specifically, in the javascript implementation I had something like:
function (doc) {
emit(doc.somefield, doc);
}
I had converted this to:
def map(doc):
yield doc.somefield, doc
However, this gave me the "no response" error you describe.
Changing it to the following fixed the problem.
def map(doc):
yield doc['somefield'], doc
I don't know there OSX keeps CouchDB config files, but you always may setup Python query server through Futon. On sidebar click Configuration, than "Add section" at the bottom of the page and fill the fields with same data as you planned to write into local.ini. As bonus, you don't need restart CouchDB - configuration changes through HTTP API are applied instantly, but be sure that you'd specified correct values.

List all hitTypes through the mturk API?

Is there a way to list all my HIT types (not HITs or assignments) using the mturk api?
I can't find any documentation on this. I'm using python, so it'd be nice if boto supported this query.
Looking through the MTurk API (http://docs.amazonwebservices.com/AWSMechTurk/latest/AWSMturkAPI/Welcome.html) I don't see anything that returns a list of HIT types. You should post a query to the MTurk forum (https://forums.aws.amazon.com/forum.jspa?forumID=11). It seems like a useful feature to add.
Unfortunately there isn't. We resort to persisting every HitType locally that we create through turk's api at houdiniapi.com which works just fine.

Categories