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

percolate query sorted by "_doc" is incorrectly matching date range query #52618

Closed
davidbkemp opened this issue Feb 21, 2020 · 3 comments · Fixed by #52758
Closed

percolate query sorted by "_doc" is incorrectly matching date range query #52618

davidbkemp opened this issue Feb 21, 2020 · 3 comments · Fixed by #52758
Labels
>bug :Search Relevance/Percolator Reverse search: find queries that match a document Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch

Comments

@davidbkemp
Copy link
Contributor

Elasticsearch version 7.5.1

Plugins installed: []

JVM version 1.8.0_232

OS version Darwin C02XF3HBJHD2 18.7.0 Darwin Kernel Version 18.7.0: Sun Dec 1 18:59:03 PST 2019; root:xnu-4903.278.19~1/RELEASE_X86_64 x86_64

Sorting a percolate search by "_doc" results in range queries being incorrectly matched.

Note: this could be related to #52617

Steps to reproduce:

  1. Create an index
PUT /myindex
{
  "mappings": {
    "properties": {
      "d": {
        "type": "date"
      },
      "q": {
        "type": "percolator"
      }
    }
  }
}
  1. Index a couple of range queries that should be mutually exclisive

PUT /myindex/_doc/1
{
  "q": {
    "bool": {
      "must": [
        {
          "range": {
            "d": {
              "gt": "now"
            }
          }
        }
      ]
    }
  }
}


PUT /myindex/_doc/2
{
  "q": {
    "bool": {
      "must": [
        {
          "range": {
            "d": {
              "lt": "now"
            }
          }
        }
      ]
    }
  }
}
  1. Perform a percolate query sorted by "_doc"
GET /myindex/_search
{
  "query": {
    "percolate": {
      "field": "q",
      "document": {
        "d": "2020-02-18T15:00:00.000+11:00"
      }
    }
  },
  "sort": [
    "_doc"
  ]
}

Expected: Only one of the saved queries should match (document id "2").

Actual: Both of the saved queries match.

Note that you do get the correct behaviour if you do not sort the results. ie.

GET /myindex/_search
{
  "query": {
    "percolate": {
      "field": "q",
      "document": {
        "d": "2020-02-18T15:05:00.000+11:00"
      }
    }
  }
}
@iverase iverase added the :Search Relevance/Percolator Reverse search: find queries that match a document label Feb 21, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Percolator)

@matriv
Copy link
Contributor

matriv commented Feb 21, 2020

Reproduces in master as well.

@matriv matriv added the >bug label Feb 21, 2020
@romseygeek
Copy link
Contributor

This is indeed the same problem as #52617, and is fixed by #52748. I'll open a PR to add specific testing for this scenario.

romseygeek added a commit that referenced this issue Feb 26, 2020
Commit #52748 fixed a bug where percolate queries wrapped in a constant score
could report incorrect matches. This commit adds a test to check that it also fixes
the case where a percolate query is sorted by something other than score.

Closes #52618
romseygeek added a commit that referenced this issue Feb 26, 2020
Commit #52748 fixed a bug where percolate queries wrapped in a constant score
could report incorrect matches. This commit adds a test to check that it also fixes
the case where a percolate query is sorted by something other than score.

Closes #52618
@javanna javanna added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Relevance/Percolator Reverse search: find queries that match a document Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants