Skip to content

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

@davidbkemp

Description

@davidbkemp

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"
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search Relevance/PercolatorReverse search: find queries that match a document>bugTeam:Search RelevanceMeta label for the Search Relevance team in Elasticsearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions