# Simple query string: minus (-) doesn't work if WHITESPACE not specified in flags

**URL:** <https://discuss.elastic.co/t/simple-query-string-minus-doesnt-work-if-whitespace-not-specified-in-flags/237347>\
**Category:** Elasticsearch\
**Created:** [June 16, 2020, 5:15pm UTC](https://discuss.elastic.co/t/simple-query-string-minus-doesnt-work-if-whitespace-not-specified-in-flags/237347 "2020-06-16T17:15:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [June 16, 2020, 5:15pm UTC](https://discuss.elastic.co/t/simple-query-string-minus-doesnt-work-if-whitespace-not-specified-in-flags/237347/1 "2020-06-16T17:15:05Z")

</div>

Hi everyone, like mentionned in the title, i'm facing the problem with simple query string when WHITESPACE is not specified in flags.  
I'm using `docker.elastic.co/elasticsearch/elasticsearch:7.4.1`  
I have a mapping like below:

```auto
PUT test 
{
  "settings": {
    "analysis": {
      "analyzer": {
        "english": {
          "type": "custom",
          "char_filter": "html_strip",
          "tokenizer": "icu_tokenizer",
          "filter": [
            "english_possessive_stemmer",
            "lowercase",
            "icu_folding",
            "english_stop",
            "english_stemmer"
          ]
        }
      },
      "filter": {
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_",
          "remove_trailing": false
        },
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "english_possessive_stemmer": {
          "type": "stemmer",
          "language": "possessive_english"
        }
      }
    }
  },
  "mappings": {
    "properties":{
      "translations":{
      "properties":{
        "en": {
          "type": "text",
          "term_vector": "with_positions_offsets",
          "analyzer": "english"
        }
      }
    },
      "elastic_translations":{
      "properties":{
        "en": {
          "type": "text",
          "analyzer": "english"
        }
      }
    },
      "elastic_case_title":{
      "properties":{
        "en": {
          "type": "text",
          "analyzer": "english"
        }
      }
    }
    }
  }
}

PUT test/_doc/1
{
  "translations": {
    "en": "one two three of four"
  },
  "elastic_translations":{
    "en": "four of five"
  },
  "elastic_case_title":{
    "en": "five of six"
  }
}

PUT test/_doc/2
{
  "translations": {
    "en": "two three of four"
  },
  "elastic_translations":{
    "en": "three of four"
  },
  "elastic_case_title":{
    "en": "five of six"
  }
}

PUT test/_doc/3
{
  "translations": {
    "en": "six of seven"
  },
  "elastic_translations":{
    "en": "three of"
  },
  "elastic_case_title":{
    "en": "eight of nine"
  }
}

```

and when i launch this request (with `default_operator: or` and `all flags enabled`) it works fine:

```auto
GET test/_search
{
  "query": {
    "bool": {
      "should": [
        {
        "simple_query_string": {
          "query": "one two of three",
          "fields": [
            "elastic_case_title.en^5",
            "elastic_translations.en^3",
            "translations.en"
          ]
        }
      }
      ]
    }
  },
  "highlight": {
    "pre_tags": [
      "<mark>"
    ],
    "post_tags": [
      "</mark>"
    ],
    "fields" : {
      "translations.en": {},
      "elastic_case_title.en": {},
      "elastic_translations.en": {}
    }
  }
}

```

but then i have another problem with **keyword** and **operator and** , so that i followed this solution:

> <https://github.com/elastic/elasticsearch/issues/39905>
>
> I use the official docker image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
> Elasticsearch version (bin/elasticsearch --version):
> Version: 6.6.1, Build: default/tar/1fd8f69/2019-02-13T17:10:04.160291Z, JVM: 11.0.1
> Plugins installed: nothing besides the default ones...

  
as solution proposed by @jimczi, i remove **WHITESPACE flag** like below:

```auto
GET test/_search
{
  "query": {
    "bool": {
      "should": [
        {
        "simple_query_string": {
          "query": "one two of three",
          "fields": [
            "elastic_case_title.en^5",
            "elastic_translations.en^3",
            "translations.en"
          ],
          "flags": "AND|ESCAPE|NEAR|NOT|OR|PHRASE|PRECEDENCE|PREFIX|SLOP",
          "default_operator": "AND"
        }
      }
      ]
    }
  },
  "highlight": {
    "pre_tags": [
      "<mark>"
    ],
    "post_tags": [
      "</mark>"
    ],
    "fields" : {
      "translations.en": {},
      "elastic_case_title.en": {},
      "elastic_translations.en": {}
    }
  }
}

```

it work fine (i have doc 1 as result) until i give the query string minus (-) (aka prohibited clause) like this:

```auto
GET test/_search
{
  "query": {
    "bool": {
      "should": [
        {
        "simple_query_string": {
          "query": "-one two of three",
          "fields": [
            "elastic_case_title.en^5",
            "elastic_translations.en^3",
            "translations.en"
          ],
          "flags": "AND|ESCAPE|NEAR|NOT|OR|PHRASE|PRECEDENCE|PREFIX|SLOP",
          "default_operator": "AND"
        }
      }
      ]
    }
  },
  "highlight": {
    "pre_tags": [
      "<mark>"
    ],
    "post_tags": [
      "</mark>"
    ],
    "fields" : {
      "translations.en": {},
      "elastic_case_title.en": {},
      "elastic_translations.en": {}
    }
  }
}

```

or this one ( i followed the solution on elastic documention, as i give a (+) before (-))

```auto
GET test/_search
{
  "query": {
    "bool": {
      "should": [
        {
        "simple_query_string": {
          "query": "+-one two of three",
          "fields": [
            "elastic_case_title.en^5",
            "elastic_translations.en^3",
            "translations.en"
          ],
          "flags": "AND|ESCAPE|NEAR|NOT|OR|PHRASE|PRECEDENCE|PREFIX|SLOP",
          "default_operator": "AND"
        }
      }
      ]
    }
  },
  "highlight": {
    "pre_tags": [
      "<mark>"
    ],
    "post_tags": [
      "</mark>"
    ],
    "fields" : {
      "translations.en": {},
      "elastic_case_title.en": {},
      "elastic_translations.en": {}
    }
  }
}

```

both queries dont work, it give me doc 2 and doc 3 (expected only doc 2) and i lost my highlight too.  
when i use explain,

```auto
GET test/_explain/3(or2)
{
  "query": {
    "bool": {
      "should": [
        {
        "simple_query_string": {
          "query": "+-one two of three",
          "fields": [
            "elastic_case_title.en^5",
            "elastic_translations.en^3",
            "translations.en"
          ],
          "flags": "AND|ESCAPE|NEAR|NOT|OR|PHRASE|PRECEDENCE|PREFIX|SLOP",
          "default_operator": "AND"
        }
      }
      ]
    }
  }
}

```

it give me nothing:

```auto
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "3",
  "matched" : true,
  "explanation" : {
    "value" : 1.0,
    "description" : "sum of:",
    "details" : [
      {
        "value" : 1.0,
        "description" : "*:*",
        "details" : []
      }
    ]
  }
}

```

i found a same issue on elastic github but no solution provided:

> <https://github.com/elastic/elasticsearch/issues/9633>
>
> Refers to scenario described in #9525
> { 
> "query":{ 
> "simple\_query\_string" : { 
> "query" : "php developer -superguru", 
> "analyzer": "my\_synonyms", 
> "fields": \["title","\_all"\], 
> "flags" :...

  
Do you guys have any explanation ?  
Otherwise, do you have any solution for filtering stopword, while using and operator ?  
@jimczi im sorry if i bother you, but your explanation in this issue is so clear, i wonder if you can help me this team. So thank you.  
Thank you guys.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 14, 2020, 5:15pm UTC](https://discuss.elastic.co/t/simple-query-string-minus-doesnt-work-if-whitespace-not-specified-in-flags/237347/2 "2020-07-14T17:15:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
