API calls inaccessible in Elasticsearch PY client

I am trying to port my code from py-elasticsearch to the official python client.

from elasticsearch import Elasticsearch, RequestsHttpConnection
es_server = ["http://server:9200/"]
es_index = "index_pattern*"
es = Elasticsearch(es_server, connection_class=RequestsHttpConnection)

I'm trying to call get_mapping and validate_query and I get the following errors:

es.get_mapping()
AttributeError: 'Elasticsearch' object has no attribute 'get_mapping'
es.validate_query()
AttributeError: 'Elasticsearch' object has no attribute 'validate_query'

Am I missing something in my import statement?

Your import statement is fine, but with elasticsearch-py the root Elasticsearch object doesn't contain that much. Most APIs are accessible through IndicesClient, ClusterClient, NodesClient, and CatClient objects. So:

es.indices.get_mapping()
es.indices.validate_query()
2 Likes

Thanks that's super helpful.

About the only thing you can get out of the root Elasticsearch object is info:

>>> from elasticsearch import Elasticsearch
>>> import json
>>> es = Elasticsearch()
>>> print json.dumps(es.info(), indent=2)
{
  "status": 200,
  "cluster_name": "elasticsearch",
  "version": {
    "lucene_version": "4.10.4",
    "build_hash": "929b9739cae115e73c346cb5f9a6f24ba735a743",
    "number": "1.7.0",
    "build_timestamp": "2015-07-16T14:31:07Z",
    "build_snapshot": false
  },
  "name": "peanut.local_01-07-22-PM",
  "tagline": "You Know, for Search"
}