MarkLogic - Query Options with extract-document-da

2019-07-25 15:04发布

MarkLogic version 9.0-6.2

I am trying to extract a portion of the envelope (example given below) using extract-document-data in Query options.

{
  "envelope": {
    "headers": {
      "audit": {
        "created-by": "admin", 
        "last-updated-by": "*******"
      }
    }, 
    "instance": {
       "UserId": "Test1",
       "UserName":"TestName"
       "Phones":[
         {
           "PhoneType":"Home",
           "PhoneNum":"18009897800"
         },
         {
           "PhoneType":"Cell",
           "PhoneNum":"1239897800"
         }
       ]
    }
  }
}

My requirement is just to return UserId and UserName. So I tried below code in Options file.

"extract-document-data":
          {
          "selected": "exclude",
          "extract-path": [ "/envelope/instance/Phones" ]
          },
"extract-document-data":
          {
          "selected": "include",
          "extract-path": [ "/envelope/instance" ]
          }

I am getting the response as below

{
"instance": {
       "UserId": "Test1",
       "UserName":"TestName"
       "Phones":[
         {
           "PhoneType":"Home",
           "PhoneNum":"18009897800"
         },
         {
           "PhoneType":"Cell",
           "PhoneNum":"123989780"
         }
       ]
    }
}

This code is not excluding the "Phones" property. Also, returning "instance" property in the output, but I just need the UserId and UserName.

How can I code both exclude and include in the same options file? Also, in the include path, how do I specify just the descendants to be returned (in my case, descendants of "instance" property.

Thanks in advance!

1条回答
孤傲高冷的网名
2楼-- · 2019-07-25 15:52

Does the response extract the right data with a specification similar to the following?

"extract-document-data": {
      "selected": "include",
      "extract-path": [
          "/envelope/instance/(UserId|UserName)"
          ]
      }

Hoping that helps,

查看更多
登录 后发表回答