Node SDK match null field in search query

We’re using the nodejs sdk v3.0.5, and in our app we’re building FTS queries using this syntax:

const name = Couchbase.SearchQuery.wildcard(`${name}*`).field('name');
const queries = [name];
const query = Couchbase.SearchQuery.conjuncts();

If I wanted to add a clause to exclude documents where a “deleted_at” field is null, how would I do that?

const notDeleted = Couchbase.SearchQuery.match(null).field('deleted_at');
const queries = [name];
const query = Couchbase.SearchQuery.conjuncts();

this produces a query object that gets added to the other clauses

{"match":null,"field":"deletedAt"}

but it doesn’t seem to affect the query results at all (I do have that field deleted_at added to my FTS index)

Any guidance on this? Seems like a normal thing to do, just not sure how to proceed.

1 Like

@ericb can you please assist ?

1 Like

Hi Schleg,

So I have a question, do all of your documents have a deleted_at field with an empty string or explicitly marked as a null value? Or is the field missing in that document? Forgive me I am exploring this issue for the first time with FTS and although this may seem obvious I’d like to make sure that I understand how to replicate your underlying data. Sorry for the delay.

Can you show the query you are using this clause in? Any additional code and context you can give .

Is it possible that you can just use a N1QL query that uses FTS?

SELECT meta().id, x.name
FROM `my-bucket` as x
WHERE SEARCH(x, {"field": "name", "match": "something*"}, {"index": "my-index"})
  AND t.iata IS NOT NULL;

Also, since FTS searches on text within a field, and not on the value of a field, I think the approach you were trying would only find fields that have an empty string as their value. I’m not sure there is any way (with an FTS search) to match on a null value, BUT I am continuing to look into this and the possibility of using a BooleanQuery.

do all of your documents have a deleted_at field with an empty string or explicitly marked as a null value? Or is the field missing in that document?

all documents have deleted_at and it’s either null or a string

Is it possible that you can just use a N1QL query that uses FTS?

yeah we do that in other places, and that’s why i know we can use a null comparison just like you suggest. it’s just this part is using the SDK builder methods and i don’t want to rewrite it if i don’t have to just to work around this common case.

i guess i could go dig around in the SDK source and see how this code actually works under the covers–trying to avoid that too :wink: