1

{"uuid": 121222151, "path": "/aaa/bbb/ccc.json", "name": "newDoc1", "uuid": 121222152, "path": "/aaa/ddd.json", "name": "newDoc1"}

I am using StructuredQueryBuilder to search for results.

StructuredQueryBuilder queryBuilder = new StructuredQueryBuilder();
StructuredQueryDefinition containPositiveQuery = queryBuilder.containerQuery(queryBuilder.jsonProperty("name"), queryBuilder.term("newDoc1"));
StructuredQueryDefinition containNegativeQuery = queryBuilder.containerQuery(queryBuilder.jsonProperty("path"), queryBuilder.term("*/bbb/*"));
StructuredQueryDefinition containQuery = qb.andNot(containPositiveQuery, containNegativeQuery);

I want the result to search for the name "newDoc1" but not in the path which contains "*/bbb/*". The above code is not working. What could be the reason?

Aravind
  • 362
  • 5
  • 11

2 Answers2

1

Your example JSON document is flat. There are no nested objects. Therefore there are no containers to query. To achieve your goal, I'm guessing your document would need to look more like this:

{ "container": {
    "uuid": 121222151,
    "path": "/aaa/bbb/ccc.json", 
    "name": "newDoc1"
  },
  "container": {
    "uuid": 121222152,
    "path": "/aaa/ddd.json", 
    "name": "newDoc1"
  }
}

And your query more like this:

StructuredQueryBuilder queryBuilder = new StructuredQueryBuilder();
StructuredQueryDefinition positiveQuery = queryBuilder.term("newDoc1");
StructuredQueryDefinition negativeQuery = queryBuilder.term("*/bbb/*");
StructuredQueryDefinition containQuery = 
  queryBuilder.containerQuery(queryBuilder.jsonProperty("container"), 
    qb.andNot(positiveQuery, negativeQuery));

I can't test this fully right now, but hopefully this starts you down the right direction.

Sam Mefford
  • 2,465
  • 10
  • 15
1

Have you turned on wildcard indexes for the path property? If not, you probably want to create a field on the path property and turn on the wildcard indexes only for that field.

To understand wildcard searches, see:

http://docs.marklogic.com/guide/search-dev/wildcard

Turning on wildcards for a specific field makes sense if you only need wildcards for that JSON property.

ehennum
  • 7,295
  • 13
  • 9