Following the example provided:
# add data to hash set
HSET movies:11002 title "Star Wars: Episode V - The Empire Strikes Back" plot "Luke Skywalker begins Jedi training with Yoda." release_year 1980 genre "Action" rating 8.7 votes 1127635
HSET movies:11003 title "The Godfather" plot "The aging patriarch of an organized crime dynasty transfers control of his empire to his son." release_year 1972 genre "Drama" rating 9.2 votes 1563839
# create index
FT.CREATE idx:movies ON hash PREFIX 1 "movies:" SCHEMA title TEXT SORTABLE release_year NUMERIC SORTABLE rating NUMERIC SORTABLE genre TAG SORTABLE
# search movies
FT.SEARCH idx:movies * SORTBY release_year ASC RETURN 2 title release_year
# search action movies
FT.SEARCH idx:movies "star @genre:{action}" RETURN 2 title release_year
# search movie that title starts with god
FT.SEARCH idx:movies @title:god* SORTBY release_year ASC RETURN 2 title release_year
# search movie that ends with father (DOESNT WORK)?
FT.SEARCH idx:movies @title:*father SORTBY release_year ASC RETURN 2 title release_year
# search movie that contains fath (DOESNT WORK)?
FT.SEARCH idx:movies @title:*fath* SORTBY release_year ASC RETURN 2 title release_year
How do I make the contains string work?
Someone mentioned AGGREGATION, but I don't know how to make this return results:
FT.AGGREGATE idx:movies "*" FILTER "contains('title', 'father')"
redis version: 6.2.7
# Modules
module:name=timeseries,ver=10611,api=1,filters=0,usedby=[],using=[],options=[handle-io-errors]
module:name=graph,ver=20813,api=1,filters=0,usedby=[],using=[ReJSON],options=[]
module:name=search,ver=20408,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
module:name=ReJSON,ver=20009,api=1,filters=0,usedby=[search|graph],using=[],options=[handle-io-errors]
module:name=bf,ver=20215,api=1,filters=0,usedby=[],using=[],options=[]
There's really two questions here but I'm happy to answer both:
How do I make the contains string work?
RediSearch doesn't support prefix wildcards, only postfix wildcards. So, using FT.SEARCH
, this is not possible.
Someone mentioned AGGREGATION, but I don't know how to make this return results.
Your call to the contains
function is not providing the field name properly. Field names are almost always prefixed with an @
. Easy mistake to make and I've made it many times myself. Try this:
FT.AGGREGATE idx:movies "*" FILTER "contains(@title, 'father')"
Hope that helps!