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

must_not doesn't work as NOT #1751

Open
sanikolaev opened this issue Jan 23, 2024 · 2 comments
Open

must_not doesn't work as NOT #1751

sanikolaev opened this issue Jan 23, 2024 · 2 comments
Assignees

Comments

@sanikolaev
Copy link
Collaborator

sanikolaev commented Jan 23, 2024

In this case when I have 4 docs like these:

➜  ~ mysql -P9306 -h0 -v -e "drop table if exists test; create table test(a int, b int); insert into test (a, b) values (0, 0),(0,1),(1,0),(1,1)"
--------------
drop table if exists test
--------------

--------------
create table test(a int, b int)
--------------

--------------
insert into test (a, b) values (0, 0),(0,1),(1,0),(1,1)
--------------

and must finds one of them:

➜  ~ curl -sX POST http://localhost:9308/search -d '
{

    "index": "test",
    "query": {
        "bool": {
            "must": [
                {
                    "equals": {
                        "a": 1
                    }
                },
                {
                    "equals": {
                        "b": 1
                    }
                }
            ]
        }
    }
}
'|jq .
{
  "took": 0,
  "timed_out": false,
  "hits": {
    "total": 1,
    "total_relation": "eq",
    "hits": [
      {
        "_id": "1515714768311156772",
        "_score": 1,
        "_source": {
          "a": 1,
          "b": 1
        }
      }
    ]
  }
}

I would expect that if I wrap it into must_not it would act as NOT and would find the other 3 docs, but it's not happening, it finds only one of them:

➜  ~ curl  -sX POST http://localhost:9308/search -d '
{

    "index": "test",
    "query": {
        "bool": {
            "must_not": [
                {
                    "bool": {
                        "must": [
                            {
                                "equals": {
                                    "a": 1
                                }
                            },
                            {
                                "equals": {
                                    "b": 1
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}
'|jq .

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

Related forum thread: https://forum.manticoresearch.com/t/how-does-must-not-work-in-queries/1782

@tomatolog
Copy link
Contributor

must_not should not work by its own unless searchd.not_terms_only_allowed enabled

@tomatolog
Copy link
Contributor

and for me the must_not query work as it should ( ! ( a==1 AND b==1 ) )

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

2 participants