mel
mel

Reputation: 2790

Requesting solr using python requests

I'm a beginner with solr, and I'm trying to retrieve all the id of all my documents that are in my cluster.

http://10.126.10.10:8980/solr/cineinfo/select?fl=mom_i&q=*:*

When I hit this URL I got this response:

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="q">*:*</str>
<str name="fl">mom_i</str>
</lst>
</lst>
<result name="response" numFound="1380" start="0">
<doc>
<int name="mom_i">2730232</int>
</doc>
<doc>
<int name="mom_i">2034019</int>
</doc>
<doc>
<int name="mom_i">2022020</int>
</doc>
<doc>
<int name="mom_i">2000015</int>
</doc>
<doc>
<int name="mom_i">2000025</int>
</doc>
<doc>
<int name="mom_i">2100022</int>
</doc>
<doc>
<int name="mom_i">2000615</int>
</doc>
<doc>
<int name="mom_i">2400027</int>
</doc>
<doc>
<int name="mom_i">2020029</int>
</doc>
<doc>
<int name="mom_i">2000128</int>
</doc>
</result>
</response>

I'm trying to request a solR cluster using python. So I did a function to retrieve all the mom_i:

def get_all_mom(number_of_document, solr_url = _solr_url):
    headers = {'content-type': "application/json" }

    json_query = {
                'query': '*:*',
                'fl':'mom_i',
                'rows': number_of_document
            }
    response  = requests.post(solr_url, data=json.dumps(json_query), headers=headers)
    response_json = response.json()
    print response_json
    return response_json

The problem is when I call the function I don't have the result I get in the browser I have an error message which is:

{u'responseHeader': {u'status': 400, u'QTime': 0, u'params': {u'json': u'{"query": "*:*", "rows": "1380"}'}}, u'error': {u'msg': u'Unknown top-level key in JSON request : fl', u'code': 400}}

If you guys could help me figure out where it come from.

Upvotes: 1

Views: 2003

Answers (1)

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

The book link list out all the parameters that need to be sent in the json ...

It show how to add them in JSON

Json API Parameter name mapping

It shows whats options are available in JSON API Parameter for the standard request parameter.

Upvotes: 1

Related Questions