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

simple_query_string parser may fail with NumberFormatException while parsing flags #7875

Closed
imotov opened this Issue Sep 25, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@imotov
Copy link
Member

imotov commented Sep 25, 2014

To reproduce:

curl -XDELETE 'http://localhost:9200/test/?pretty'

curl -XPUT 'http://localhost:9200/test/?pretty' -d '{
  "settings": {
    "index.number_of_shards": 1
  },
  "mappings": {
    "document": {
      "_routing" : {
        "required": true
      },
      "properties": {
        "title": {
          "type": "string"
    }
      }
    },
    "entity": {
      "_parent": {
        "type": "document"
      },
      "_routing" : {
        "required": true
      },
      "properties": {
        "body": {
          "type": "string"
        }
      }
    }
  }
}'


curl -XPOST 'http://localhost:9200/_bulk?pretty' --data-binary '
{"index": {"_index": "test", "_type": "document", "_id" : "1", "_routing": "1"}}
{"title": "New document"}
{"index": {"_index": "test", "_type": "entity", "_id" : "1", "_routing": "1", "_parent": "1"}}
{"body": "document body"}
'
curl -XPOST 'http://localhost:9200/test/_refresh?pretty'
curl -XGET 'http://localhost:9200/test/document/_search?pretty' -d '
{
  "query" : {
    "bool": {
      "minimum_should_match": 1,
      "disable_coord": true,
      "should": [
        {
          "simple_query_string": {
            "query": "old document",
            "default_operator": "and",
            "fields": ["title^10"],
            "flags": "NONE"
          }
        },
        {
          "has_child": {
            "query": {
              "bool": {
                "minimum_should_match": 1,
                "disable_coord": true,
                "should": [
                  {
                    "simple_query_string" : {
                      "query" : "\"document body\"~2",
                      "default_operator" : "and",
                      "flags": "PHRASE|SLOP",
                      "fields": ["body^5"]
                    }
                  },
                  {
                    "simple_query_string" : {
                      "query" : "document body",
                      "default_operator" : "and",
                      "fields": ["body"],
                      "flags": "NONE"
                    }
                  }
                ]
              }
            },
            "type": "entity",
            "score_mode": "sum"
          }
        }
      ]
    }
  }
}
'

The search fails with NumberFormatException[For input string: \"PHRASE|SLOP\"]; exception.

The problem occurs because simple_query_string parser is using XContentParser.hasTextCharacters() method to check for the presence of text in the token, while this method should be only used to detect internal presentation of the string.

The issue was originally reported on the mailing list https://groups.google.com/forum/#!topic/elasticsearch-ru/SeiifNQW-qo

@imotov imotov added the >bug label Sep 25, 2014

@imotov imotov self-assigned this Sep 25, 2014

imotov added a commit to imotov/elasticsearch that referenced this issue Sep 26, 2014

Fix NumberFormatException in Simple Query String Query
Incorrect usage of XContentParser.hasTextCharacters() can result in NumberFormatException as well as other possible issues in template query parser and phrase suggest parsers.

Fixes elastic#7875

@imotov imotov closed this in #7876 Sep 26, 2014

imotov added a commit that referenced this issue Sep 26, 2014

Fix NumberFormatException in Simple Query String Query
Incorrect usage of XContentParser.hasTextCharacters() can result in NumberFormatException as well as other possible issues in template query parser and phrase suggest parsers.

Fixes #7875

imotov added a commit that referenced this issue Sep 26, 2014

Fix NumberFormatException in Simple Query String Query
Incorrect usage of XContentParser.hasTextCharacters() can result in NumberFormatException as well as other possible issues in template query parser and phrase suggest parsers.

Fixes #7875

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Fix NumberFormatException in Simple Query String Query
Incorrect usage of XContentParser.hasTextCharacters() can result in NumberFormatException as well as other possible issues in template query parser and phrase suggest parsers.

Fixes elastic#7875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.