-
-
Save bracki/1508084 to your computer and use it in GitHub Desktop.
ElasticSearch via Thrift and Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t | |
twitter][tweet][123], source[]}] | |
org.elasticsearch.ElasticSearchParseException: Failed to derive xcontent from (offset=0, length=1): [-128] | |
at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:147) | |
at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:49) | |
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:428) | |
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:414) | |
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:302) | |
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:181) | |
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:487) | |
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:400) | |
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) | |
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) | |
at java.lang.Thread.run(Thread.java:662) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from elasticsearch import Rest | |
>>> from elasticsearch.ttypes import * | |
>>> from elasticsearch.constants import * | |
>>> from thrift import Thrift | |
>>> from thrift.transport import TSocket | |
>>> from thrift.transport import TTransport | |
>>> from thrift.protocol import TBinaryProtocol | |
>>> dir() | |
['Method', 'Rest', 'RestRequest', 'RestResponse', 'Status', 'TApplicationException', 'TBinaryProtocol', 'TException', 'TMessageType', 'TProcessor', 'TProtocol', 'TSocket', 'TTransport', 'TType', 'Thrift', '__builtins__', '__doc__', '__name__', 'fastbinary', 'sys'] | |
>>> Status | |
<class elasticsearch.ttypes.Status at 0x7f6996107f50> | |
>>> dir(Status) | |
['ACCEPTED', 'BAD_GATEWAY', 'BAD_REQUEST', 'CONFLICT', 'CONT', 'CREATED', 'EXPECTATION_FAILED', 'FAILED_DEPENDENCY', 'FORBIDDEN', 'FOUND', 'GATEWAY_TIMEOUT', 'GONE', 'INSUFFICIENT_STORAGE', 'INTERNAL_SERVER_ERROR', 'LENGTH_REQUIRED', 'LOCKED', 'METHOD_NOT_ALLOWED', 'MOVED_PERMANENTLY', 'MULTIPLE_CHOICES', 'MULTI_STATUS', 'NON_AUTHORITATIVE_INFORMATION', 'NOT_ACCEPTABLE', 'NOT_FOUND', 'NOT_IMPLEMENTED', 'NOT_MODIFIED', 'NO_CONTENT', 'OK', 'PARTIAL_CONTENT', 'PAYMENT_REQUIRED', 'PRECONDITION_FAILED', 'PROXY_AUTHENTICATION', 'REQUESTED_RANGE_NOT_SATISFIED', 'REQUEST_ENTITY_TOO_LARGE', 'REQUEST_TIMEOUT', 'REQUEST_URI_TOO_LONG', 'RESET_CONTENT', 'SEE_OTHER', 'SERVICE_UNAVAILABLE', 'SWITCHING_PROTOCOLS', 'TEMPORARY_REDIRECT', 'UNAUTHORIZED', 'UNPROCESSABLE_ENTITY', 'UNSUPPORTED_MEDIA_TYPE', 'USE_PROXY', '_NAMES_TO_VALUES', '_VALUES_TO_NAMES', '__doc__', '__module__'] | |
>>> RestRequest.__doc__ | |
'\n Attributes:\n - method\n - uri\n - parameters\n - headers\n - body\n ' | |
>>> Method | |
<class elasticsearch.ttypes.Method at 0x7f6996107ef0> | |
>>> Method.GET | |
0 | |
>>> Method.Gasd | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: class Method has no attribute 'Gasd' | |
>>> transport = TSocket.TSocket('192.168.1.128', 9500) | |
>>> transport = TTransport.TBufferedTransport(transport) | |
File "<stdin>", line 1 | |
transport = TTransport.TBufferedTransport(transport) | |
^ | |
IndentationError: unexpected indent | |
>>> transport = TTransport.TBufferedTransport(transport) | |
>>> protocol = TBinaryProtocol.TBinaryProtocol(transport) | |
>>> client = Rest.Client(protocol) | |
>>> transport.open() | |
>>> dir(client) | |
['__doc__', '__init__', '__module__', '_iprot', '_oprot', '_seqid', 'execute', 'recv_execute', 'send_execute'] | |
>>> request = RestRequest(Method.GET, "/twitter/tweet/2") | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> client.execute(request) | |
RestResponse(status=200, headers=None, body='{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"exists":true, "_source" : {\n "user": "kimchy",\n "post_date": "2009-11-15T14:12:12",\n "message": "You know, for Search"\n}}') | |
>>> dir(request) | |
['__doc__', '__eq__', '__init__', '__module__', '__ne__', '__repr__', 'body', 'headers', 'method', 'parameters', 'read', 'thrift_spec', 'uri', 'write'] | |
>>> request = RestRequest(Method.PUT, "/twitter/tweet/123") | |
>>> request.__doc__ | |
'\n Attributes:\n - method\n - uri\n - parameters\n - headers\n - body\n ' | |
>>> request = RestRequest(Method.PUT, "/twitter/tweet/123", body={'foo':'bar'}) | |
>>> client.execute(request) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "elasticsearch/Rest.py", line 39, in execute | |
self.send_execute(request) | |
File "elasticsearch/Rest.py", line 46, in send_execute | |
args.write(self._oprot) | |
File "elasticsearch/Rest.py", line 141, in write | |
self.request.write(oprot) | |
File "elasticsearch/ttypes.py", line 292, in write | |
oprot.writeString(self.body) | |
File "/var/lib/python-support/python2.5/thrift/protocol/TBinaryProtocol.py", line 123, in writeString | |
self.trans.write(str) | |
File "/var/lib/python-support/python2.5/thrift/transport/TTransport.py", line 164, in write | |
self.__wbuf.write(buf) | |
TypeError: write() argument 1 must be string or read-only character buffer, not dict | |
>>> import json | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
ImportError: No module named json | |
>>> import simplejson | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
ImportError: No module named simplejson | |
>>> request = RestRequest(Method.PUT, "/twitter/tweet/123", body="{'foo':'bar'}") | |
>>> client.execute(request) | |
RestResponse(status=500, headers=None, body='{"error":"ElasticSearchParseException[Failed to derive xcontent from (offset=0, length=1): [-128]]","status":500}') | |
>>> request = RestRequest(Method.PUT, "/twitter/tweet/123", body='{"foo":"bar"}') | |
>>> client.execute(request) | |
^CTraceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "elasticsearch/Rest.py", line 40, in execute | |
return self.recv_execute() | |
File "elasticsearch/Rest.py", line 51, in recv_execute | |
(fname, mtype, rseqid) = self._iprot.readMessageBegin() | |
File "/var/lib/python-support/python2.5/thrift/protocol/TBinaryProtocol.py", line 126, in readMessageBegin | |
sz = self.readI32() | |
File "/var/lib/python-support/python2.5/thrift/protocol/TBinaryProtocol.py", line 203, in readI32 | |
buff = self.trans.readAll(4) | |
File "/var/lib/python-support/python2.5/thrift/transport/TTransport.py", line 58, in readAll | |
chunk = self.read(sz-have) | |
File "/var/lib/python-support/python2.5/thrift/transport/TTransport.py", line 160, in read | |
self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size))) | |
File "/var/lib/python-support/python2.5/thrift/transport/TSocket.py", line 94, in read | |
buff = self.handle.recv(sz) | |
KeyboardInterrupt | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment