问题
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:
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,
来源:https://stackoverflow.com/questions/53638681/marklogic-query-options-with-extract-document-data