Skip to content
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

Recurring Boolean field in Redis json key value breaks document in index #668

Closed
shashirangam opened this issue Sep 14, 2024 · 5 comments
Closed

Comments

@shashirangam
Copy link

shashirangam commented Sep 14, 2024

Hi,

Page Redis-indexing document

There is an open issue in stack over flow regarding "Recurring Boolean field in Redis json key value breaks document in index". Is there any solution for this one. I am also facing same issue. Recently we implemented Redis-search in our spring boot application, but stuck with this limitation. Thank you in advance for your quick response.

Link: Recurring Boolean field in Redis json key value breaks document in index

@shashirangam shashirangam changed the title Feedback: Indexing Recurring Boolean field in Redis json key value breaks document in index Sep 14, 2024
@mich-elle-luna
Copy link
Collaborator

Hello,

I tried to find a solution with our chat app
https://redis.io/chat

When dealing with recurring boolean fields in JSON arrays in Redis, you may encounter issues if trying to index and search them as TAG fields. Below is a recommended approach to properly index and search these boolean fields.
Sample JSON Document:

{
"ACompanies": [
{ "APurchaseNeed": true, "Name": "Company1" },
{ "APurchaseNeed": false, "Name": "Company2" },
{ "APurchaseNeed": true, "Name": "Company3" }
]
}

Steps to Create the Index and Search:

Create the Index: Use the JSONPath wildcard operator to handle multiple nodes in arrays.

FT.CREATE myIndex ON JSON PREFIX 1 doc: SCHEMA $.ACompanies[*].APurchaseNeed AS APurchaseNeed TAG

Add the Document:

JSON.SET doc:1 $ '{"ACompanies":[{"APurchaseNeed":true,"Name":"Company1"},{"APurchaseNeed":false,"Name":"Company2"},{"APurchaseNeed":true,"Name":"Company3"}]}'

Search the Document:

FT.SEARCH myIndex "@APurchaseNeed:{true}"

Important Points:

Using JSONPath Wildcard: The key part is using the wildcard in the JSONPath ($.ACompanies[*].APurchaseNeed) to index every occurrence of APurchaseNeed within the array items.
Boolean as TAG: Tagging boolean values ensures that each APurchaseNeed is correctly indexed and can be searched efficiently.

By following these steps, you should be able to index and search recurring boolean fields within JSON arrays without issues.

For further details, refer to the Redis documentation on indexing JSON arrays.

@shashirangam
Copy link
Author

Thanks for the quick response. I have tried the same as mentioned, but it doesn't worked for me. Here I am attaching the video for reference.
Below command also giving no results
FT.SEARCH myIndex *
image

I am using the redis-stack latest version using docker

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -v "D:/storage:/data:rw" redis/redis-stack:latest

If I am not using the version which works fine for the solution provided, Please guide me to use the right version.
Thank you in advance for your quick response.

redis-search-boolean.mp4

@shashirangam
Copy link
Author

Seems this issue resolved in redis-om-python but not working with direct Redis queries.
Reference link for the similar issue
Can you reply me when it is going to fix.

@mich-elle-luna
Copy link
Collaborator

Hello again,

Sorry for the delay, I think you may have better luck getting help with your question on our discord server. Here are the instructions to join and ask your question/get help to solve your issue: https://redis.io/learn/community/discord

@dwdougherty
Copy link
Collaborator

I'm not expecting any further activity, so I'm closing this ticket.

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

3 participants