FT.CREATE with FILTER expression ON JSON?

According to the documentation, it is possible to use filter expression like in the FT.AGGREGATE to create a partial index.
However, I could not figure out how to create a partial index on JSON-type keys.
Is it possible?
Do somebody has experience in it?

What do mean by “partial index”?
You can use FILTER with JSON.

Used the “partial” term to refer further filtering on the content of the key’s data.
The PREFIX is ok to filter on the keys and would like to filter the elements in the index on the content.

Example:
Creating an index without filtering and using FT.SEARCH to count the serviceId:“workflow” items:

FT.CREATE index ON JSON PREFIX 1 config: SCHEMA $.config.serviceId AS serviceId TAG
FT.SEARCH index * @serviceId:{workflow} LIMIT 0 0

returns 23.
Trying to filter out only that 23 keys into the index:

FT.CREATE index ON JSON PREFIX 1 config: filter "@serviceId=='workflow'" SCHEMA $.config.serviceId AS category TAG
FT.SEARCH index * LIMIT 0 0

returns 0.

I took your example and it seems to work OK

127.0.0.1:6379> FT.CREATE index ON JSON PREFIX 1 config: SCHEMA $.config.serviceId AS serviceId TAG
OK
127.0.0.1:6379> json.set config:1 $ '{"config":{"serviceId":"workflow"}}'
OK
127.0.0.1:6379> FT.SEARCH index @serviceId:{workflow} LIMIT 0 0
1) (integer) 1
127.0.0.1:6379> FT.SEARCH index @serviceId:{workflow}
1) (integer) 1
2) "config:1"
3) 1) "$"
   2) "{\"config\":{\"serviceId\":\"workflow\"}}"
127.0.0.1:6379> FT.CREATE index2 ON JSON PREFIX 1 config: FILTER "@serviceId=='workflow'"  SCHEMA $.config.serviceId AS serviceId TAG
OK
127.0.0.1:6379> FT.SEARCH index2 @serviceId:{workflow} LIMIT 0 0
1) (integer) 1
127.0.0.1:6379> FT.SEARCH index2 @serviceId:{workflow}
1) (integer) 1
2) "config:1"
3) 1) "$"
   2) "{\"config\":{\"serviceId\":\"workflow\"}}"

Thank you very much!
Has been checked with the latest redis-stack version and it worked for me too.
My previous test has been made on a compiled version of RediSearch ( RESP.app displays ver=20207).
The problem is hidden somewhere in that RediSearch version.

1 Like