Skip to content

Constant score percolate query incorrectly matching date range query  #52617

@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

A percolate search wrapped in a constant score query seems to incorrectly match range queries.

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 constant-score percolate query
GET /myindex/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "percolate": {
          "field": "q",
          "document": {
            "d": "2020-02-18T15:00:00.000+11:00"
          }
        }
      }
    }
  }
}

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 use constant_score.
i.e. the following search gives the expected behaviour.

GET /myindex/_search
{
  "query": {
    "percolate": {
      "field": "q",
      "document": {
        "d": "2020-02-18T15:05:00.000+11:00"
      }
    }
  }
}

Metadata

Metadata

Assignees

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