skip to Main Content

Very new to REDIS, and having issues using JSON/Index/Query that is driving me crazy.

Example struct

public class MyType implements Serializable {
{
    @SerializedName("myval")
    @Expose
    private Integer myval;
    @SerializedName("status")
    @Expose
    private String status;
}

I am easily using redis-stack, and pushing in this class using JSON/GSON.

Problem comes when I try to query.

I have an index set up that looks like

 Schema testSchema = new Schema().addTextField("$.status",1.0);
 myJedis.ftCreate("STATUSINDEX",IndexOperations().setDefault(rule),testSchema);

I then insert a few json blobs, some with status="on", and others with status="OFF"

Using redisInsight/Browser, I can see my json, with status ON and OFF as set in previous.

Using redisInsight/RediSearch:
If I search using
FT.SEARCH "STATUSINDEX" ‘@&.status:OFF’
I get the json objects with status ‘OFF’ as expected.

If I search using
FT.SEARCH "STATUSINDEX" ‘@&.status:ON’
I get nothing.

If I repeat the test, but substitute "MYON" instead of "ON" when inserting the objects, then the search:
FT.SEARCH "STATUSINDEX" ‘@&.status:MYON’
returns the expected json objects.

I must be doing something wrong, or the value ‘on’ is reserved??

TIA, Wayne

Tried many different tests and combinations of status types. Only seems to happen using "ON"

2

Answers


  1. I suspect the reason is that you’ve defined the ‘status’ field as text in the index’s schema. The text type is used for free-text searches, and as such has the notion of "stop words" – common words that are ignored – and "on" is probably there.

    You should use a tag field instead.

    Login or Signup to reply.
  2. Since your data model uses fields that you want to match such as @status, you can map them as TAG (instead of TEXT) since TAG field is a simpler tokeniser and it’s ideal for this type of use case. You can check more details here https://redis.io/docs/interact/search-and-query/query/exact-match/

    If still need to use as TEXT. This behaviour is because Redis has a list of words that aren’t tokenised. After all, their grammar meaning is less relevant in full-text search context or appears too often such as articles, prepositions, conjunctions etc… they are treated as STOPWORDS. Applicable only for TEXT fields. You can see the list here likewise how to customise it: https://redis.io/docs/interact/search-and-query/advanced-concepts/stopwords/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search