0

I construct below payload in MarkLogic REST API:

"query": {
    "jsonPropertyRangeQuery": {
        "property": "rangeChange",
        "operator": ">",
        "value": 60
    }
}

It throws error: "messageCode":"MANAGE-INVALIDPAYLOAD", "message":"MANAGE-INVALIDPAYLOAD: (err:FOER0000) Payload has errors in structure, content-type or values. XDMP-QUERYNODE: cts:query(object-node{\"property\":text{\"rangeChange\"}, \"operator\":text{\">\"}, \"value\":text{\"60\"}}) -- Query element object-node{\"property\":text{\"rangeChange\"}, ...} contains unknown child"}}

If I do below, then it goes through

"query": {
    "jsonPropertyValueQuery": {
        "property": "city",
        "value": "Chicago"
     }
}

Any thought?

Robert
  • 7,394
  • 40
  • 45
  • 64
Fiona Chen
  • 1,358
  • 5
  • 16

2 Answers2

0

Try using a structured-query instead:

"query": {
  "range-query": {
    "json-property": "city",
    "value": "Chicago",
    "range-operator": "GT"
  }
}

See also: https://docs.marklogic.com/guide/search-dev/structured-query#id_83393

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
0

One footnote on Geert's answer clarifying that a top key of "query" contains a structured query....

First, given that "percentChange" doesn't appear in the question, that's probably a different issue.

Anyway, to send the JSON serialization of a cts.query() to the /v1/search endpoint, the key containing the cts.query() should be "ctsquery" instead of "query" so the REST API knows how to deserialize the query.

Hoping that helps,

ehennum
  • 7,295
  • 13
  • 9
  • Still doesn't work: "message":"MANAGE-INVALIDPAYLOAD: (err:FOER0000) Payload has errors in structure, content-type or values. XDMP-AS: (err:XPTY0004) $query as cts:query -- Invalid coercion: () as cts:query"}} . Below is payload for JSON range query: "ctsquery": { "range-query": { "json-property": "percentChange", "range-operator": "GT", "value": "60" } }, – Fiona Chen Nov 25 '19 at 17:29
  • MANAGE-INVALIDPAYLOAD indicates that the query is being sent to the Management REST API on port 8002 instead of the application REST API. For the structured query case, the value of "query" should be "queries": [...] -- for the syntax, see http://docs.marklogic.com/guide/search-dev/structured-query#id_32225 and for an example, see http://docs.marklogic.com/guide/search-dev/structured-query#id_83674 . For the cts.query() case, see https://docs.marklogic.com/10.0/guide/rest-dev/search#id_30577 – ehennum Nov 25 '19 at 21:03
  • Error: "message":"MANAGE-INVALIDPAYLOAD: (err:FOER0000) Payload has errors in structure, content-type or values. XDMP-NOTQUERY: cts:query(object-node{\"range-query\":object-node{\"type\":text{\"xs:decimal\"}, \"json-property\":text{\"percentChange\"}, ...}}) -- Element object-node{\"range-query\":object-node{...}} is not a query (expecting a cts:query)"}} – Fiona Chen Nov 25 '19 at 22:40
  • I stand corrected. My suggestions were entirely about the /v1/search endpoint. I'm not familiar with the alerting payloads accepted by the Managed REST API. – ehennum Nov 25 '19 at 23:23
  • Final Push Using JS Module !!! WORKS!!! But still DOESN'T WORK in REST API. The actually representation is this: percentChange 60 – Fiona Chen Nov 27 '19 at 00:01
  • (Namespace suggestion deleted because StackOverflow formatting was merely hiding part of the bound URI.) – ehennum Nov 27 '19 at 16:21