POST json request to Solr with cursorMark in request
Asked Answered
B

2

6

Is it possible to include cursorMark value in POST request's body instead of sending it as query string parameter?

The following query:

{"query":"val:abc","limit":10,"cursorMark":"*","sort":"id asc"}

returns an error with the message: "Unknown top-level key in JSON request : cursorMark"

Burney answered 2/2, 2017 at 16:35 Comment(1)
how do you send this request?Linearity
B
5

According to Solr Json Request API documentation, every query string parameter has a corresponding POST request parameter in JSON API, e.g. q -> query, start -> offset, etc.

However, there is no equivalent parameter for cursorMark query string parameter.

The best solution I am aware of is changing request type from application/json to application/x-www-form-urlencoded which allows using query string parameters in POST request's body. The reason why I was using application/json was to get json response, but it turns that it is controlled by wt=json parameter.

  1. Changed query uri to: http://localhost:8983/solr/myCore/select?wt=json
  2. Changed POST request parameters back to query string counterparts, i.e. q, start, rows, etc.
  3. UrlEncoded the query string.
  4. Put the encoded query string in POST body.
  5. Changed request content type to application/x-www-form-urlencoded.
Burney answered 19/5, 2017 at 8:2 Comment(1)
Thanks for answer! Can you please add code snippet as an example? I am not sure how to set content-type parameter in solr query using solrJ.ThanksRenelle
B
1

https://solr.apache.org/guide/7_7/json-request-api.html#passing-parameters-via-json says that you can augment a JSON-based POST with non-JSON params. I got this to work in 2022 with a JSON query that includes "params": {"cursorMark": "*"}, without needing to resort to changing the request type (as suggested in the accepted answer).

Broomfield answered 6/1, 2022 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.