i have added a json document into my redis db using JSON.set Below given is my Json SET command
{
"books": [
{
"title": "Peter Pan",
"price": 8.95
},
{
"title": "Moby Dick",
"price": 12.99
}
]
}
JSON.SET myDoc $ '{"books": [{"title": "Peter Pan", "price": 8.95},{"title": "A Thousand Suns", "price": 8.15}, {"title": "Moby Dick", "price": 12.99}]}'
Now i want to search this specific array of objects to fetch me the records which have price greater and equal to 8
i have tried creating an index but it always return me 0 records Below given is my index
FT.CREATE docIdx ON JSON SCHEMA $.myDoc.books.price AS price Numeric
in the way you propose the index, you're ignoring the array of elements that belong to the object book. One way could be:
or
another recommendation it's to use the prefix since all documents with the same prefix will be indexed by Redisearch.
Something like:
Notice, since you are trying to match the condition within the same document when you search for your price condition (between 8 and 9), the result will be the entire document "myDoc" with all the books, since the "Peter Pan" and "A Thousand Suns" matches the query condition. Such as: