I have a simple entry as such :
json.set a:1 . '{"name":"chloe", "age":26 , "foo" : {"bar" : 1}'
When creating an index I can go as far as
FT.CREATE ON JSON SCHEMA $.name AS name TEXT .....
However bar
is a dynamic value and it can be changed. How can I create an index for a dynamic value under foo
?
2
Answers
You can use full JSONPath syntax to match fields in the JSON. If the property
foo
will always contain an object and that object will always contain one and only one property, you could use a JSONPath$.foo.*
like this:Note that this JSONPath could very well return multiple results if
foo
contains more than one property:This could be desirable if your field is a TAG field and the JSON contained strings instead of numbers. But it won’t work for a NUMERIC field.
You can try a JSONPath such as
$.foo.*
, which would match all immediate children of top-levelfoo
.If there are multiple children, support for multi values will be available with RediSearch 2.6.1.
If children are of different types, you can try using a filter to avoid indexing failures due to type mismatch, for example,
'$.foo.[?(@.*>-999)]'
, to handle specific numeric values, or'$.foo.[?(@.*!="")]'
to handle text values.