Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search documents based on one of it's properties in marklogic using rest api

I wanted to search documents based on one of it's property using rest api in marklogic. Here is the document -

{
   "id" : "101",
   "sectionName" : "PI"
   "firstName" : "I",
   "middle name" : "Me",
   "last name : "Myself",
   "emailId" : "[email protected]" 
}

Lets say, i want to search documents based on sectionName and order by id then what will be my rest query?

like image 217
RCS Avatar asked Oct 30 '22 01:10

RCS


1 Answers

If you want to order by id, you must first create a range index on id in the Admin UI.

  • http://docs.marklogic.com/guide/admin/range_index

Then, you can submit a search request with the sectionName as criteria and the id for sort order:

  • http://docs.marklogic.com/guide/rest-dev/search#id_84389
  • http://docs.marklogic.com/guide/search-dev/structured-query#id_39758
  • http://docs.marklogic.com/guide/search-dev/appendixa#id_44212
  • http://docs.marklogic.com/REST/POST/v1/search

Something along the following lines should work:

{"search":{
    "query":{"queries":[{
        "value-query":{
            "json-property":"sectionName",
            "text":["PI"],
            "term-option":["exact"]
            }
        }]},
    "options":{
        {"sort-order":{"json-property":"id"}}
        }
    }}

Hoping that helps,

like image 81
ehennum Avatar answered Jan 04 '23 14:01

ehennum