MarkLogic - Query Options with extract-document-data

不想你离开。 提交于 2020-01-06 03:47:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!