2
votes

I am new to Marklogic and probably missing something. I'm using MarkLogic 7.0, java-client-api 2.0.5. Having created a new REST instance, I'm trying to run sample code offered by Marklogic:

DatabaseClient client = 
  DatabaseClientFactory.newClient("some.host.com", 8006, "user", "****", 
    DatabaseClientFactory.Authentication.DIGEST);
JSONDocumentManager doc = client.newJSONDocumentManager();
doc.write(
  "hello.json", 
  new StringHandle("{\"recipient\": \"world\", \"message\": \"Hello, world!\"}"));

QueryManager query = client.newQueryManager();
StructuredQueryBuilder b = query.newStructuredQueryBuilder();
SearchHandle results = 
  query.search(
    b.and(b.term("hello"), b.value(b.jsonKey("recipient"), "world")), 
    new SearchHandle());  
for (MatchDocumentSummary summary : results.getMatchResults()) {
    System.out.println(doc.read(summary.getUri(), new StringHandle()).toString());
}

But I am getting the following error

com.marklogic.client.FailedRequestException: Local message: search failed: Bad Request. Server Message: REST-INVALIDPARAM: (err:FOER0000) Invalid parameter: Invalid query structure (check namespace): <query xmlns:search="http://marklogic.com/appservices/search" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><and-query><term-query><text>hello</text></term-query><value-query><json-key>recipient</json-key><text>world</text></value-query></and-query></query>
at com.marklogic.client.impl.JerseyServices.search(JerseyServices.java:1893)
at com.marklogic.client.impl.JerseyServices.search(JerseyServices.java:1703)
at com.marklogic.client.impl.QueryManagerImpl.search(QueryManagerImpl.java:199)
at com.marklogic.client.impl.QueryManagerImpl.search(QueryManagerImpl.java:162)

What is the reason of that? Is that because of some server configuration and I need to adjust the code somehow? (I don't have admin rights and have MarkLogic server already configured)

P.S. After I installed MarkLogic on another machine and ran the same code there, it worked fine.

Thanks, Hlib

UPDATE:

  1. Server logs doesn't provide any additional information
  2. Everything works fine if I put "search" namespace in each tag.
1
What version of MarkLogic 7.0? java-client-api 2.0.5 should only be used against MarkLogic Server 7.0-5. For what it's worth, when I try your code against MarkLogic Server 7.0-5 with java-client-api 2.0.5, it works for me. - Sam Mefford
Also, how do you put "search" namespace in each tag? Do you mean directly against the REST endpoint? Or using a RawStructuredQueryDefintion? The error definitely is missing a namespace on the XML, but I can't understand how it could have gotten that way from StructuredQueryBuilder nor how you're able to put a namespace in each tag via StructuredQueryBuilder. - Sam Mefford
Have you tried this with a minimal classpath? I'm thinking you might have something on your classpath that causes XMLStreamWriter (used by StructuredQueryBuilder) to misbehave and not use the default namespace github.com/marklogic/java-client-api/blob/2.0-develop/src/main/… - Sam Mefford
@Sam, thanks. After running with the minimal classpath, i found out that it was woodstox library that was causing the issue - Hlib Babii

1 Answers

1
votes

I removed woodstox library from the classpath. As mentioned by @SamMefford it was causing XMLStreamWriter to misbehave. After that everything works fine.