Skip to content

Node client search response corrupted when there are exactly 2 JSON items stored and using a limit size of 1 #3056

@SamBeroz

Description

@SamBeroz

Description

I want to update to the 5.X client but the attached code isn't working (it does work on 4.7.0). When I have 2 JSON items stored and search for the first item based on an aliased property in the JSON object it returns a mangled response. It works as expected if I have only 1 item or more than 2 items stored but when I have exactly 2 items stored it's a problem. Also it only seems to happen with a limit with a size of 1.

The response I would expect is:
{"total":2,"documents":[{"id":"test:itemA","value":{"itemOrder":1}}]}
However the response I get is:
{"total":2,"documents":[{"id":"test:itemA","value":{}},{"id":["itemOrder","1","$","{\"itemOrder\":1}"],"value":{}}]}

The problem query is:

  const result = await client.ft.search(indexName, "@itemOrder:[0 10]", {
    SORTBY: {
      BY: "itemOrder",
      DIRECTION: "ASC",
    },
    LIMIT: {
      from: 0,
      size: 1, //Using a limit of 1 here seems to be a problem when there are two items stored
    },
  });

where my index is:

    await client.ft.create(
      indexName,
      {
        "$.itemOrder": {
          type: "NUMERIC",
          AS: "itemOrder",
        },
      },
      {
        ON: "JSON",
        PREFIX: getKey(""),
      }
    );

The full code that demonstrates the issue is attached.

Node.js Version

v22.12.0

Redis Server Version

redis_version:7.4.3

Node Redis Version

[email protected]

Platform

Windows and Linux

Logs

Connected to Redis
First item with 1 entry:
result: {"total":1,"documents":[{"id":"test:itemA","value":{"itemOrder":1}}]}
found item: [Object: null prototype] { itemOrder: 1 }
Second item with 2 entries:
result: {"total":2,"documents":[{"id":"test:itemA","value":{}},{"id":["itemOrder","1","$","{\"itemOrder\":1}"],"value":{}}]}
found item: [Object: null prototype] {}
found item: [Object: null prototype] {}
Third item with 3 entries:
result: {"total":3,"documents":[{"id":"test:itemA","value":{"itemOrder":1}}]}
found item: [Object: null prototype] { itemOrder: 1 }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions