Ruby Kannan
Ruby Kannan

Reputation: 251

Is it possible to query or sort the document based on the size of an array inside the json document in marklogic?

{
  "name": "ruby",
  "phone": [
    {
      "type": "mobile",
      "number": 12345678
    },
    {
      "type": "office",
      "number": 2433242
    }
  ]
}

My problem here is, I just want to sort the documents like the one mentioned above based on the size of phone array.

Upvotes: 1

Views: 47

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66723

You could create a Template Driven Extraction (TDE) with a column that has the size of the phone array, and then search and sort with the Optic API.

Unfortunately, you cannot simply create a path-range-index with the following XPath, because it isn't an indexable XPath expression:

/array-node('phone')/count(node())

Upvotes: 1

Related Questions