Skip to content

MatchNoDocsQuery in simple_query_string query with unmapped field and AND operator returning no results #34708

@robinroestenburg

Description

@robinroestenburg

Elasticsearch version (bin/elasticsearch --version):

Version: 6.4.2, Build: oss/tar/04711c2/2018-09-26T13:34:09.098244Z, JVM: 1.8.0_171

Plugins installed:

[analysis-icu]

JVM version (java -version):

openjdk version "1.8.0_171"
OpenJDK Runtime Environment (IcedTea 3.8.0) (Alpine 8.171.11-r0)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

OS version (uname -a if on a Unix-like system):

Linux 387e0b185f37 4.4.0-135-generic #161-Ubuntu SMP Mon Aug 27 10:45:01 UTC 2018 x86_64 Linux

Description of the problem including expected versus actual behavior:
Related to the issue described in #28856 and #33427, when I execute a simple_query_string with the following conditions:

  • the query string is analyzed with a standard analyzer
  • the query contains a token (e.g. &) that is ignored by the standard analyzer
  • the query has multiple fields configured
  • not all fields exist in the mapping and document
  • the default_operator is AND

The token is not found in any of the fields but for fields that do not exist in the mapping a MatchNoDocsQuery is returned instead of omitting the token. The combination with the AND operator ensures that no result will match, regardless of what is queried.

The expected behavior is for the token to be removed from the token stream, not to be replaced by MatchNoDocsQuery.

Steps to reproduce:

  1. Create an index with multiple fields:
$ curl -X PUT -H "Content-Type: application/json" "http://localhost:9200/unmapped-field-test" -d '{
  "mappings": {
    "doc": {
      "properties": {
        "title": { "type": "text" },
        "body": { "type": "text" }
      }
    }
  }
}'
  1. Validate the query:
$ curl -X POST -H "Content-Type: application/json" "http://localhost:9200/unmapped-field-test/doc/_validate/query?explain" -d '{
  "query": {
    "simple_query_string": {
      "query": "risk & impact analysis",
      "fields": ["title", "title_en_us", "body"],
      "default_operator": "AND"
    }
  }
}'

This results in the following error:

{
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "valid": true,
  "explanations": [
    {
      "index": "unmapped-field-test",
      "valid": true,
      "explanation": "+(+(title:risk | body:risk | MatchNoDocsQuery(\"unmapped field [title_en_us]\"))~1.0 +MatchNoDocsQuery(\"unmapped field [title_en_us]\") +(title:impact | body:impact | MatchNoDocsQuery(\"unmapped field [title_en_us]\"))~1.0 +(title:analysis | body:analysis | MatchNoDocsQuery(\"unmapped field [title_en_us]\"))~1.0) #*:*"
    }
  ]
}
  1. After creating a document containing the field:
$ curl -X POST -H "Content-Type: application/json" "http://localhost:9200/unmapped-field-test/doc" -d '{
  "title": "foo",
  "title_en_us": "foo_en_us",
  "body": "bar"
}'
  1. The above query no longer returns an error (as it is now present in the mapping):
$ curl -X POST -H "Content-Type: application/json" "http://localhost:9200/unmapped-field-test/doc/_validate/query?explain" -d '{
  "query": {
    "simple_query_string": {
      "query": "risk & impact analysis",
      "fields": ["title", "title_en_us", "body"],
      "default_operator": "AND"
    }
  }
}'
{
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "valid": true,
  "explanations": [
    {
      "index": "unmapped-field-test",
      "valid": true,
      "explanation": "+(+(title:risk | body:risk | title_en_us:risk)~1.0 +(title:impact | body:impact | title_en_us:impact)~1.0 +(title:analysis | body:analysis | title_en_us:analysis)~1.0) #*:*"
    }
  ]
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions