Skip to content

Using AND for the default_operator in a query_string doesn't appear to be working unless term is quoted #30131

@ontology-rory

Description

@ontology-rory

Elasticsearch version: 6.2.1

Plugins installed: []

JVM version:

openjdk version "1.8.0_162"
OpenJDK Runtime Environment (Zulu 8.27.0.7-linux64) (build 1.8.0_162-b01)
OpenJDK 64-Bit Server VM (Zulu 8.27.0.7-linux64) (build 25.162-b01, mixed mode)

OS version: Linux 3.10.0-514.10.2.el7.x86_64 #1 SMP Fri Mar 3 00:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:

Using AND for the default_operator in a query_string doesn't appear to be working unless term is quoted.

If I run a query I would expect to get 1 document back for, I get zero results. If I quote one of the terms I then get the required result. For example, searching for 3150185 J3050 versus 3150185 "J3050":

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

versus

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.5753642,
    "hits": [
      {
        "_index": "index-test",
        "_type": "document",
        "_id": "test",
        "_score": 0.5753642,
        "_source": {
          "meNm": [
            "3150185"
          ],
          "label": [
            "J3050",
            "JD050"
          ],
          "name": [
            "JD050_ABCD_13"
          ]
        }
      }
    ]
  }
}

Steps to reproduce:

  • create a document
PUT index-test/document/test
{
  "meNm": ["3150185"],
  "label": ["J3050","JD050"],
  "name": ["JD050_ABCD_13"]
}
  • run query below and get 0 results
GET index-test/_search
{
  "query": {
    "query_string": {
      "query": "3150185 J3050",
      "default_operator": "AND"
    }
  },
  "explain": false, 
  "from": 0,
  "size": 10
}
  • run query below and get 1 result
GET index-test/_search
{
  "query": {
    "query_string": {
      "query": "3150185 \"J3050\"",
      "default_operator": "AND"
    }
  },
  "explain": false, 
  "from": 0,
  "size": 10
}

Note that putting the explicit AND in gives the expected result:

GET index-test/_search
{
  "query": {
    "query_string": {
      "query": "3150185 AND J3050"
    }
  },
  "explain": false, 
  "from": 0,
  "size": 10
}

gives

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.5753642,
    "hits": [
      {
        "_index": "index-test",
        "_type": "document",
        "_id": "test",
        "_score": 0.5753642,
        "_source": {
          "meNm": [
            "3150185"
          ],
          "label": [
            "J3050",
            "JD050"
          ],
          "name": [
            "JD050_ABCD_13"
          ]
        }
      }
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions