# Behavior of + in Simple Query Strings vs. Query Strings

**URL:** <https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823>\
**Category:** Elasticsearch\
**Created:** [June 23, 2016, 7:21pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823 "2016-06-23T19:21:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drs/32/8001_2.png) [@drs](https://discuss.elastic.co/u/drs)\
**Post date:** [June 23, 2016, 7:21pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823/1 "2016-06-23T19:21:38Z")

</div>

Does the `+` operator behave differently under `simple_query_string` queries than under `query_string` queries?

The `simple_query_string` documentation says:

> - `+` signifies AND operation

From my testing and from the way this is worded, it seems like in `simple_query_string`, the `+` is effectively replaced with `AND`. This is different than how the `+` behaves in `query_string` queries.

In other words, does this mean that

```auto
'simple_query_string': {
    'query': 'book +case'
}

```

is the same as

```auto
'query_string': {
    'query': 'book AND case'
}

```

but is **not** the same as

```auto
'query_string': {
    'query': 'book +case'
}

```

?

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [June 23, 2016, 7:39pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823/2 "2016-06-23T19:39:46Z")

</div>

Boolean clauses in Elasticsearch (and Lucene the underlying library) are applied to single search terms, not pairs. The AND, OR etc operators are for convenience and map to the single search term operators of must, should, not.

So `book AND case` should actually be better understood as `+book +case`. Both are "must" clauses. Both are required terms. On the other hand, `book +case` should be thought of as one should clause (results that match should rank higher) and one must clause (all results should contain this term).

Anyways

- `book AND case` == `+book +case` == `MUST(book) MUST(case)`
- `book +case` == `SHOULD(book) MUST(case)`

---

<div class="post-metadata">

**Author:** ![drs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drs/32/8001_2.png) [@drs](https://discuss.elastic.co/u/drs)\
**Post date:** [June 23, 2016, 7:43pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823/3 "2016-06-23T19:43:25Z")

</div>

Right, thank you. But I'm seeing that the behavior for `simple_query_string` queries differ. It seems like the `+` in `book +case` on `simple_query_string` acts like an `AND` operator, and behaves the same as `book AND case` (or `+book +case`) on `query_string` queries.

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [June 23, 2016, 7:52pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823/4 "2016-06-23T19:52:45Z")

</div>

You're right, my apologies for not reading thoroughly enough. For what it's worth, I can confirm what you're seeing by running this against query validation endpoint

```auto
GET test/_validate/query?explain=true
{
    "query": {
        "simple_query_string": {
           "query": "foo +bar"
        }
    }
}

```

It does appear both terms are mandatory, I get back the Lucene query `"explanation": "+_all:foo +_all:bar"`

---

<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 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/behavior-of-in-simple-query-strings-vs-query-strings/53823/5 "2017-07-05T22:40:59Z")

</div>


