I am connecting to an AWS elasticsearch server and trying to fetch only one field in the response. In addition, I am not aware of the format but I am sure it works with the normal curl
/ postman
requests.
The code :
import collections
from time import sleep
import requests
import simplejson as json
from aws_requests_auth.aws_auth import AWSRequestsAuth
from elasticsearch import Elasticsearch, RequestsHttpConnection, helpers
from pyelasticsearch import ElasticSearch, bulk_chunks
es = ElasticSearch(urls='http://'+es_host,
port=80)
auth = AWSRequestsAuth(aws_access_key='XXXXXXXX',
aws_secret_access_key='XXXXXXXXX',
aws_host=es_host,
aws_region='us-west-2',
aws_service='es')
es_client = Elasticsearch(host=es_host,
port=80,
connection_class=RequestsHttpConnection,
http_auth=auth)
print (es_client.info())
print (es_client.count(index='X_data'))
result = es_client.search(index='X_data', body={"terms":{'field':"pid"}})
print (result)
This gives below format error. Any changes to fetch only PID field as results?
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 105, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.RequestError: TransportError(400, u'parsing_exception')