How do I prevent documents from being indexed?
Last updated 22, Mar 2024
Question
How do I prevent documents from being indexed?
Answer
To prevent keys from being indexed, you can create a FILTER
at index creation time.
FT.CREATE item_idx ON JSON PREFIX 1 item: FILTER '@__key!="item:2"' SCHEMA id AS id NUMERIC
Copy code
Test now adding records:
JSON.SET item:1 $ '{"id":1}'
JSON.SET item:2 $ '{"id":2}'
JSON.SET item:3 $ '{"id":3}'
Copy code
And verify that FT.INFO item_idx
reports the number of indexed keys:
9) num_docs
10) "2"
Copy code
You can also verify that an index scan does not return the filtered key:
FT.SEARCH item_idx * RETURN 0
1) (integer) 2
2) "item:1"
3) "item:3"
Copy code
References
Learn more about the FILTER
expression.