Skip to content

Search returns empty result #3603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shoang22 opened this issue Apr 15, 2025 · 2 comments
Closed

Search returns empty result #3603

shoang22 opened this issue Apr 15, 2025 · 2 comments

Comments

@shoang22
Copy link

Hello,

I'm trying to add documents to redis and query them with Redisearch:

async def test_redis(db: redis.Redis):
    source_name = "my_source"
    schema = (
        TextField("type"),
        TextField("page"),
        TextField("text"),
    )
    await db.ft(source_name).create_index(
        schema, 
        definition=IndexDefinition(prefix=[f"{source_name}:"], index_type=IndexType.HASH)
    )
    text = ["a" * 100] * 50
    async with db.pipeline(transaction=True) as pipe:
        for i, _text in enumerate(text):
            doc = {"type": "paragraph", "page": i, "text": _text}
            await pipe.hset(f"doc:{i}", mapping=doc)
        await pipe.execute()

    print(await db.ft(source_name).search(Query("@type: paragraph").dialect(2)))

this returns Result{0 total, docs: []}.

But when I use db.hgetall I get my document as expected.

@petyaslavova
Copy link
Collaborator

Hi @shoang22, can you please try to execute the search with a little sleep added after the create_index has returned. It might take a while to have your index fully functional. Recently, I was chasing a flaky test and the described behavior was the root cause.

@shoang22
Copy link
Author

yep, that did the trick! thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants