Error while using query parameter in scroll api


(Amit Pandita) #1

Hi Group,

I am using Elasticsearch Helpers Scan API to output all bulk records from my index.
I wanted to use the query parameter to filter the certain records first and then use scan for which I referred to the standard doc for scan here . But as soon as I apply the query parameter it gives me a 400 error. Here is my line of code and error.

Script:

import elasticsearch
import elasticsearch.exceptions
import elasticsearch.helpers as helpers
import time

es = elasticsearch.Elasticsearch(['54.151.244.153'],retry_on_timeout=True)

scanResp = helpers.scan(client=es,scroll="5m",query="{'match': {'channel_id': '34'}}",index='stg-index',timeout="10m",size=500)

resp={}
start_time = time.time()
for resp in scanResp:
data = resp
#print data.values()[3]

print("--- %s seconds ---" % (time.time() - start_time))

Output:

RequestError: TransportError(400, u"SearchPhaseExecutionException[Failed to execute phase [init_scan], all shards failed; shardFailures {[lEAncRHvQHKpPqlfw1NWEQ][stg-godam][0]: SearchParseException[[stg-godam][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{'match': {'channel_id': '34'}}]]]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@4cbfbcfa; line: 1, column: 3]]; }{[lEAncRHvQHKpPqlfw1NWEQ][stg-godam][1]: SearchParseException[[stg-godam][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{'match': {'channel_id': '34'}}]]]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@4cbfbcfa; line: 1, column: 3]]; }{[lEAncRHvQHKpPqlfw1NWEQ][stg-godam][2]: SearchParseException[[stg-godam][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{'match': {'channel_id': '34'}}]]]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@4cbfbcfa; line: 1, column: 3]]; }{[lEAncRHvQHKpPqlfw1NWEQ][stg-godam][3]: SearchParseException[[stg-godam][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{'match': {'channel_id': '34'}}]]]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@4cbfbcfa; line: 1, column: 3]]; }{[lEAncRHvQHKpPqlfw1NWEQ][stg-godam][4]: SearchParseException[[stg-godam][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{'match': {'channel_id': '34'}}]]]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@4cbfbcfa; line: 1, column: 3]]; }]")

Looked on the internet but not sure what I have done wrong here.

Any help is appreciated


(system) #2