5

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" : "aaa@gmail.com" 
}

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

RCS
  • 1,370
  • 11
  • 27

2 Answers2

2

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

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

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,

ehennum
  • 7,295
  • 13
  • 9
  • Thanks for answer ehennum. I am new to marklogic. By looking at all these documentation, i am getting confused.I need to make rest call so, need curl statement to search for above requirement. Can you tell me what exactly i have to use among them. – RCS Jun 14 '16 at 18:09
  • The last link above has examples of curl calls at the end of the article. The JSON fragment above is an example of the curl payload. To sort, you do need to create the range index as described in the first link. – ehennum Jun 14 '16 at 20:04
0

You can create element range index for any attribute in your document and i suppose you have saved the matadata in ML and document URI you have.

Below example should work ,, correct me if i am wrong..

http://localhost:8000/v1/documents?uri=18128a68-8d67-4726-bed4-784ee84a4d44&category=metadata