Search code examples
marklogicmarklogic-8

Marklogic - I want do element search using java api with key-value within array section of the json document


I want to search for element with key-value from array element section of the document. Lets say i have json looks like -

{ 
   "name":"abc", 
   "lastName":"xyz", 
   "description":"aaaaa aaaa", 
   "dob":11-10-1988,
   "workInformation":[
       {
          "address":"kolkata", 
          "workFor":"vvv Pvt Ltd"
       },
        {
          "address":"bangalore", 
          "workFor":"www Pvt Ltd"
       }
    ]
}

Lets say i want to search using java api inside array property workInformation for below mentioned key and value -

key - workFor, value - vvv Pvt Ltd

Please let me know, how to do it.

Thanks for reading.


Solution

  • One easy way is to use StructuredQueryBuilder.value. For example:

    StructuredQueryBuilder sqb = new StructuredQueryBuilder();
    QueryDefinition query = sqb.value(sqb.jsonProperty("workFor"), "vvv Pvt Ltd");
    

    Another option is to use QBE.