Bhanu
Bhanu

Reputation: 419

MarkLogic - Search based on the path of JSON object (without using path range index)

MarkLogic : 9.0-6.2

We have a JSON document as below, in customer entity.

"CustomerInfo": {
  "IdInfo": {
     "CustomerId":"12345"
  }, 
  "PartyRltp": {
      "CustomerId":"45678"
  }
}

My need is to search the document based on CustomerId at the specific path CustomerInfo.IdInfo.CustomerId

So if I search for "12345", the above document should be returned. But if I search with "45678", the above document should NOT be returned.

I created path range index and used cts.pathRangeQuery('/CustomerInfo/IdInfo/CustomerId','=', '12345'). However, realized that path range indexes are very expensive, so looking for a way to achieve without path range index.

Thanks in advance!

Upvotes: 1

Views: 132

Answers (1)

grtjn
grtjn

Reputation: 20414

I think you are looking for cts.jsonPropertyScopeQuery:

cts.jsonPropertyScopeQuery(
  'IdInfo',
  cts.jsonPropertyValueQuery(
    'CustomerId',
    '12345'
  )
)

HTH!

Upvotes: 3

Related Questions