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

SQL: IN does not behave as expected #38424

Closed
paulcarey opened this issue Feb 5, 2019 · 4 comments · Fixed by #38440
Closed

SQL: IN does not behave as expected #38424

paulcarey opened this issue Feb 5, 2019 · 4 comments · Fixed by #38440

Comments

@paulcarey
Copy link

Using ES 6.5.4 I would expect queries of the form WHERE foo = 'a' OR foo = 'b' to return exactly the same results as WHERE foo IN ('a', 'b'). However, this is not what I'm observing.

Running my queries through /translate shows a material difference in how these are generated.

Using IN:

  "query": {
    "terms": {
      "foo": [
        "a",
        "b"
      ],
      "boost": 1
    }
  }

Using repeated OR clauses:

  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "foo.keyword": {
              "value": "a",
              "boost": 1
            }
          }
        },
        {
          "term": {
            "foo.keyword": {
              "value": "b",
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },

What really seems to matter here though is that using OR causes ES to refer to the .keyword instance of a field that contains the following mapping:

          "foo": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },

If I modify my IN query to WHERE foo.keyword IN ('a', 'b') then the results are as expected.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@costin
Copy link
Member

costin commented Feb 5, 2019

Thanks for the report. We'll look into it however it is unlikely the fix will be backported all the way to the 6.5.x line.

@paulcarey
Copy link
Author

That's fine, thanks. I have my eyes set on 6.7 and the support for combining group by and order by!

matriv added a commit to matriv/elasticsearch that referenced this issue Feb 5, 2019
Add resolution to the exact keyword field (if exists) for text fields.
Add proper verification and error message if underlying keyword doesn't
exist.
Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

Fixes: elastic#38424
@jasontedor jasontedor added v8.0.0 and removed v7.0.0 labels Feb 6, 2019
matriv added a commit that referenced this issue Feb 6, 2019
)

- Add resolution to the exact keyword field (if exists) for text fields.
- Add proper verification and error message if underlying keyword
doesn'texist.
- Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

Fixes: #38424
@matriv
Copy link
Contributor

matriv commented Feb 6, 2019

@paulcarey Thanks for reporting! The fix will be available in the releases marked by the version labels in the issue and the relevant PR.

matriv added a commit that referenced this issue Feb 6, 2019
)

- Add resolution to the exact keyword field (if exists) for text fields.
- Add proper verification and error message if underlying keyword
doesn'texist.
- Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

Fixes: #38424
matriv added a commit that referenced this issue Feb 6, 2019
)

- Add resolution to the exact keyword field (if exists) for text fields.
- Add proper verification and error message if underlying keyword
doesn'texist.
- Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

Fixes: #38424
matriv added a commit that referenced this issue Feb 6, 2019
)

- Add resolution to the exact keyword field (if exists) for text fields.
- Add proper verification and error message if underlying keyword
doesn'texist.
- Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

Fixes: #38424
matriv added a commit that referenced this issue Feb 6, 2019
)

- Add resolution to the exact keyword field (if exists) for text fields.
- Add proper verification and error message if underlying keyword
doesn'texist.
- Move check for field attribute in the comparison list to the
`resolveType()` method of `IN`.

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

Successfully merging a pull request may close this issue.

7 participants