Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marklogic 8 xml search

Tags:

marklogic

Suppose I have a xml as below:

<xx>
    <yy>
        <name>A</name>
        <value>1</value>
    </yy>

    <yy>
        <name>A</name>
        <value>2</value>
    </yy>

    <yy>
        <name>B</name>
        <value>1</value>
    </yy>
</xx>

Now I want to find if any 'yy' is present with name as A and value as 1. So here the matching content would be:

<yy>
    <name>A</name>
    <value>1</value>
</yy>

I am trying to do this by REST call,qbe GET request but not able to do it. Can some one help me out using:

/v1/qbe
or
/v1/search
like image 464
Ankit Goel Avatar asked Apr 21 '26 05:04

Ankit Goel


1 Answers

With the /v1/search API you'll need to use custom search options to achieve this.

To upload custom search options to MarkLogic: http://developer.marklogic.com/learn/rest/custom-search#search-using-an-element-value-constraint

Your search options will define constraints for your search based on the indexes you created. Your search options should look like this:

<options xmlns="http://marklogic.com/appservices/search">
  <constraint name="yy">
    <element-query name="yy" ns="" />
  </constraint>
  <constraint name="name">
    <value>
      <element ns="" name="name"/>
    </value>
  </constraint>
  <constraint name="value">
    <value>
      <element ns="" name="value"/>
    </value>
  </constraint>
</options>

Let's say you upload these options as "mySearchOptions".

Finally, you can make this GET request to get the search results you want:

http://localhost:REST_SERVER_PORT/v1/search?q=yy%3A(name%3Aa%20AND%20value%3A1)&options=mySearchOptions

like image 196
Rob S. Avatar answered Apr 30 '26 12:04

Rob S.