RCS
RCS

Reputation: 1432

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?

Upvotes: 5

Views: 198

Answers (2)

user7006501
user7006501

Reputation: 21

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

Upvotes: 0

ehennum
ehennum

Reputation: 7335

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,

Upvotes: 2

Related Questions