javaredisjedis

JEDIS/REDIS 'ON' Keyword or broken query?


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"


Solution

  • 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.