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

Search by JSON keys works incorrectly #2115

Closed
8 tasks done
Nick-S-2018 opened this issue Apr 30, 2024 · 4 comments
Closed
8 tasks done

Search by JSON keys works incorrectly #2115

Nick-S-2018 opened this issue Apr 30, 2024 · 4 comments
Assignees

Comments

@Nick-S-2018
Copy link
Collaborator

Nick-S-2018 commented Apr 30, 2024

Bug Description:

If a JSON object's key is a negative number and we use this key in a search filter, the search returns an empty result:

curl localhost:9308/cli -d 'create table t(a json)'
Query OK, 0 rows affected (0.002 sec)

curl localhost:9308/insert -d '{"index":"t","doc":{"a":{"-1":1,"1":2}}}'
{"_index":"t","_id":6776061509853249548,"created":true,"result":"created","status":201}

curl localhost:9308/search -d '{"index":"t","query":{"in":{"any(a.-1)":[1]}}}'
{"took":0,"timed_out":false,"hits":{"total":0,"total_relation":"eq","hits":[]}}

curl localhost:9308/search -d '{"index":"t","query":{"in":{"any(a.1)":[2]}}}'
{"took":0,"timed_out":false,"hits":{"total":1,"total_relation":"eq","hits":[{"_id":"6776061509853249548","_score":1,"_source":{"a":{"-1":1,"1":2}}}]}}

Manticore Search Version:

Manticore 6.2.13 419ecf7aa@24042801 dev

Operating System Version:

Ubuntu 22.04.4 LTS

Have you tried the latest development version?

  • Yes

Internal Checklist:

To be completed by the assignee. Check off tasks that have been completed or are not applicable.

  • Task estimated
  • Specification created, reviewed, and approved
  • Implementation completed
  • Tests developed
  • Documentation updated
  • Documentation proofread
  • Changelog updated
@sanikolaev
Copy link
Collaborator

Escaping with backticks doesn't help either:

➜  ~ curl localhost:9308/search -d '{"index":"t","query":{"in":{"any(a.`-1`)":[1]}}}'

{"took":0,"timed_out":false,"hits":{"total":0,"total_relation":"eq","hits":[]}}%

➜  ~ tail -1 /opt/homebrew/var/log/manticore/query.log
/* Wed May 01 10:51:45.434 2024 conn 1146 (127.0.0.1:54192) real 0.000 wall 0.000 found 0 */  /*{"index":"t","query":{"in":{"any(a.`-1`)":[1]}}} */

@tomatolog
Copy link
Contributor

these works

mysql> select in (a.1, 2) as c from t where c=1;
+------+
| c    |
+------+
|    1 |
+------+

mysql> select in (a.`-1`, 1) as c from t where c=1;
+------+
| c    |
+------+
|    1 |
+------+
mysql> select * from t where a.`-1` in (1);
+---------------------+----------------+
| id                  | a              |
+---------------------+----------------+
| 8577531596112920577 | {"-1":1,"1":2} |
+---------------------+----------------+
mysql> select * from t where a.`1` in (2);
+---------------------+----------------+
| id                  | a              |
+---------------------+----------------+
| 8577531596112920577 | {"-1":1,"1":2} |
+---------------------+----------------+

but this not

mysql> select in (a.-1, 1) as c from t where c=1;
ERROR 1064 (42000): P01: syntax error, unexpected $undefined, expecting ',' or ')' near '.-1, 1) as c from t where c=1'

@tomatolog
Copy link
Contributor

the query curl localhost:9308/search -d '{"index":"t","query":{"in":{"any(a.-1)":[1]}}}' got parsed with filter a.1 in (1) and produces the result set

{"took":0,"timed_out":false,"hits":{"total":0,"total_relation":"eq","hits":[]}}

however when I use backticks as described here #2115 (comment) it work fine with master daemon and the version Manticore 6.2.13 419ecf7aa@24042801 dev works fine - the query {"index":"t","query":{"in":{"any(a.-1)":[1]}}} parsed as it should with filter

a.`-1` in (1)

produce correct result set

{
  "took": 0,
  "timed_out": false,
  "hits": {
    "total": 1,
    "total_relation": "eq",
    "hits": [
      {
        "_id": "8577531596112920577",
        "_score": 1,
        "_source": {
          "a": {
            "-1": 1,
            "1": 2
          }
        }
      }
    ]
  }
}

@tomatolog tomatolog assigned Nick-S-2018 and unassigned tomatolog May 21, 2024
@Nick-S-2018
Copy link
Collaborator Author

I confirm it works correctly when using backticks for negative numbers.

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

No branches or pull requests

3 participants