0

I want to run the the below query to get the particular portion of JSON:

cts:search(/user/userdetail, cts:word-query("test1"))

in java using Marklogic Java API.

Above query gives me perfect result but I want to write code in java using Marklogic java client.

Below is the json file:

{
  "user": {
    "userdetail": [
      {
        "username": "test",
        "firstName": "testName",
        "lastName": "testLastName",
        "maritalStatus": "Unmarried",
        "password": "testPassword"
      },
      {
        "username": "test1",
        "firstName": "testName1",
        "lastName": "testLastName2",
        "maritalStatus": "married",
        "password": "testPassword1"
      }
    ]
  }
}

1 Answer 1

1
QueryManager queryMgr = databaseClient.newQueryManager();
RawCombinedQueryDefinition query = queryMgr.newRawCombinedQueryDefinitionAs(Format.JSON,
  "{\"search\": {" +
  "  \"qtext\": \"test1\"," +
  "  \"options\": {" +
  "    \"searchable-expression\": {" +
  "      \"text\": \"/user/userdetail\"" +
  "    }," +
  "    \"transform-results\": {\"apply\": \"raw\"}" +
  "}}}"
);
JsonNode jsonResponse = queryMgr.search(query, new JacksonHandle()).get();
JsonNode firstMatch = jsonResponse.path("results").path(0).path("content");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.