I am trying to execute the below code from my application. But it is not giving me proper results. I am not sure, whether I am using proper handle and query definition in the code. Can someone please help me on this issue?
QueryManager queryManager = queryManager(ClientRole.GT_CONTRIBUTOR);
JSONDocumentManager docMgr = jsonDocumentManager(ClientRole.GT_CONTRIBUTOR);
CtsQueryBuilder ctsQueryBuilder = queryManager.newCtsSearchBuilder();
CtsQueryExpr ctsQueryExpr =
ctsQueryBuilder.cts.pathRangeQuery(
"/id",
"=",
"141433");
CtsQueryDefinition ctsQueryDefinition = ctsQueryBuilder.newCtsQueryDefinition(ctsQueryExpr);
JacksonHandle jacksonHandle = new JacksonHandle();
RawCombinedQueryDefinition rawQueryDef =
queryManager.newRawCombinedQueryDefinition(new StringHandle( ctsQueryDefinition.serialize()).withFormat(Format.JSON)); rawQueryDef.setCollections(GuestTrackerConstants.SEGMENT_COLLECTION);
docMgr.setPageLength(1000);
DocumentPage docPage = docMgr.search(rawQueryDef, 1, jacksonHandle);
I think you'll find StructuredQueryBuilder to be easier to use - try something like this:
You can easily add a collection via query.setCollections as well.
Edited - you mentioned you need to use CtsQueryExpr. Here's an example of getting that to work:
Note that JacksonHandle will give you back a JsonNode. You can use StringHandle if you just need a String. You can also use SearchHandle to obtain a bunch of methods to get you access to data in the search response.