FTS - match documents where a field is not defined

Hi!,
I have a question about how to implement an FTS query. I have documents where we store metadata (which are mainly key/value as string).

{
 metadata: {
   "test": "true"
 }
}

I need to match or find all the documents where the metadata field does not have the field “test” defined.
I know that with N1QL is possible, but not sure if there is an equivalent query in FTS.
Thanks!

One way to achieve this is using the must_not clause of the boolean query. Here’s how that’d look -

{
  "query": {
    "must_not": {
      "disjuncts": [
        {
          "field": "metadata.test",
          "wildcard": "*"
        }
      ]
    }
  }
}

With this query you’d be requesting for documents that do not contain anything (wildcard) within the field metadata.test. This won’t be the most performant query, but it should get you what you’re looking for.

N.b. in the SDKs this is represented with a BooleanQuery and its mustNot() method.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.