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:
> FT.CREATE a:index ON JSON SCHEMA $.name AS name TEXT $.foo.* AS num NUMERIC
OK
> FT.SEARCH a:index "@num:[1 1]"
1) (integer) 1
2) "a:1"
3) 1) "$"
2) "{\"name\":\"chloe\",\"age\":26,\"foo\":{\"bar\":1}}"
Note that this JSONPath could very well return multiple results if foo
contains more than one property:
{
"name" : "chloe",
"age": 26,
"foo": {
"bar": 1,
"baz": 13
}
}
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.