FTS searching on empty field

I have a document with a structure like this:

{
  "id": "2fa80bae-2eed-4291-bb78-09cdb7d80003",
  "pp": "text",
  "ii": ""
}

the field ii is indexed in the FTS as keyword

when I try from the PHP SDK to search all the documents with ii being “” I get no results:

$conjunctionQuery[] = (new MatchSearchQuery("")) ->field("ii");

I am doing a ConjunctionSearchQuery, so this is just a part of the query

I tried with MatchPhraseSearchQuery and MatchSearchQuery but none seems to work correctly. the ii can be either empty, or it can conain an UUID of the format: “2fa80bae-2eed-4291-bb78-09cdb7d80003”

What can I do to be able to find the documents with either an empty field “” or an UUID?

FTS does not differentiate between missing fields or null values during search. So searching for empty field content is unfortunately something we don’t support.

N1QL however can - you can look into creating a secondary index and running SQL-like queries via the query workbench to help you here with IS_NULL or IS_MISSING.

so, there is no way in which I could exclude the results with empty field? (not returning results with something in the field)

not sure if is clear. If I have a a search results with 5000 rows, from these 5000, 150 have this field empty. isn’t any option to return just the 4850 results?

Sorry if I wasn’t clear, FTS automatically excludes documents where the “field”'s value is empty or where the “field” is missing.

Here’s a sample query that does this …

{"query": {"match_all": {}}, "fields": ["special_field"]}

This query will emit out the “special_field” content (where available) alongside the document IDs in the hits section of the search response.

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