1

I'm trying to use the below code. But configuration setup not yet mentioned here. Searched so many blogs but not found.

from redisearch import Client, TextField, IndexDefinition, Query

# Creating a client with a given index name
client = Client("myIndex")

# IndexDefinition is available for RediSearch 2.0+
definition = IndexDefinition(prefix=['doc:', 'article:'])

# Creating the index definition and schema
client.create_index((TextField("title", weight=5.0), TextField("body")), definition=definition)

# Indexing a document for RediSearch 2.0+
client.redis.hset('doc:1',
                mapping={
                    'title': 'RediSearch',
                    'body': 'Redisearch impements a search engine on top of redis'
                })

# Indexing a document for RediSearch 1.x
client.add_document(
    "doc:2",
    title="RediSearch",
    body="Redisearch implements a search engine on top of redis",
)

# Simple search
res = client.search("search engine")

# the result has the total number of results, and a list of documents
print(res.total) # "2"
print(res.docs[0].title) # "RediSearch"

# Searching with complex parameters:
q = Query("search engine").verbatim().no_content().with_scores().paging(0, 5)
res = client.search(q)

I'm getting the below error like this:

redis.exceptions.ResponseError
redis.exceptions.ResponseError: unknown command `FT.SEARCH`, with args beginning with: `myIndex`, `search engine`, `LIMIT`, `0`, `10`,
Suresh
  • 85
  • 1
  • 13
  • Reference github link here: https://github.com/RediSearch/redisearch-py – Suresh Feb 01 '21 at 13:10
  • See [this issue](https://github.com/StackExchange/StackExchange.Redis/issues/1284). You must ensure the redis server has the redisearch module loaded. If you're using docker there is a specific image, mentioned in that thread, which has the module built in, simply launch it with: `docker run -p 6379:6379 redislabs/redisearch:latest` – v25 Feb 01 '21 at 14:14
  • Even this docker also showing some issues. – Suresh Feb 08 '21 at 13:16
  • Please update question with those issues! – v25 Feb 08 '21 at 16:39
  • Agreed! but I'm trying to use this setup in my directory instead of using the redisearch directory. – Suresh Feb 09 '21 at 07:23

0 Answers0