Extracting data from MarkLogic db using Java Client API when fetching one document may be dependent upon other documents

别说谁变了你拦得住时间么 提交于 2019-12-11 05:09:05

问题


I have started working on the MarkLogic database using the Java Client API. I have two use cases for me :-

  1. Extract all the documents which are in the same collection and which are in the form of JSON where a particular date is less than or equal to a certain date.

JSON is in the form

{
    "id"  : "12345"
    "date" : "2012-12-12",
    "messageType" : "dummy_type",
    ....
}

I am able to do this using the below code :-

val queryMgr = client.newQueryManager();
var rawHandle: StringHandle = new StringHandle
rawHandle.withFormat(Format.JSON).set("{\"$query\": {\"tradingDate\": { \"$le\":\""+ date + "\"}, \"$filtered\": true}}");
var querydef: RawQueryByExampleDefinition = queryMgr.newRawQueryByExampleDefinition(rawHandle);  
querydef.setCollections(collectionName);
jsonDocMgr.search(querydef, 1); 
  1. Now I have multiple documents in the database, where multiple documents are part of one id but there message types are different. As in I have A, B and C as message types with all have id as 12345. Now depending upon the date parameter in type C, I want to make a decision whether all documents (A, B, and C) need to be fetched or should not be fetched.

    Could anyone please suggest whether I can create javascript functions and pass it to the MarkLogic db using the Java Client API or any other thing or any references?


回答1:


I'd recommend you start by looking at transforming search results. To use them you'll need to follow the instructions to install and test the transform via REST or Java, then add querydef.setResponseTransform(new ServerTransform("yourTransformName") then call QueryManager.search(querydef, new SearchHandle()). You can decide what your transform should return for each query match.



来源:https://stackoverflow.com/questions/41850049/extracting-data-from-marklogic-db-using-java-client-api-when-fetching-one-docume

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