# Query\_string with "+" operator

**URL:** <https://discuss.elastic.co/t/query-string-with-operator/208308>\
**Category:** Elasticsearch\
**Created:** [November 18, 2019, 12:08pm UTC](https://discuss.elastic.co/t/query-string-with-operator/208308 "2019-11-18T12:08:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [November 18, 2019, 12:08pm UTC](https://discuss.elastic.co/t/query-string-with-operator/208308/1 "2019-11-18T12:08:36Z")

</div>

Hi there,

I have an issue related to `query_string` using the "+" operator. Suppose that my index contains the documents below:

```
  doc_1
  {
     field1: "foo bar",
     field2: "zoo"
  }

  doc_2
  {
     field1: "foo",
     field2: "bar"
  }

```

Now, consider the following query\_string:

```
{
    query_string:{
        query: foo bar
        fields: [field1^5, field2],
        default_operator: 'AND'
    }
}

```

Executing it, only the first document is returned, as foo and bar only occurs in one field (I'm not using quotation marks!)

If I change my query term to foo + bar

```
{
    query_string:{
        query: foo + bar
        fields: [field1^5, field2],
        default_operator: 'AND'
    }
}

```

both documents are returned, as the second document contains foo in one field and bar in another field.

My point is: Why should I force the "+" operator do have the second result, as I'm not using quotations in the first query? It seems that the "+" operator is much more than just force the terms to be presented in the document, it, somehow, tells the query\_string to find the occurrence of them across the fields (I don't intend to use `multi_match cross_field` DSL!)  
I'm asking that, because it's something that is not clear in the reference:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html)  
which says that, the "+" operator is similar to the `default_operator = 'AND'`.

Am I wrong?? What have I missed in my first `query_string` to have the terms searched across the fields and not the obligation to have all of them presented in one field??

Thanks,

Guilherme

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [November 18, 2019, 12:38pm UTC](https://discuss.elastic.co/t/query-string-with-operator/208308/2 "2019-11-18T12:38:10Z")

</div>

This issue was discussed here: [Confusing documentation on Query String Query on the split by whitespace behaviour · Issue #29148 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/29148#issuecomment-376458216)!

I'm using elasticsearch 6.5, that's why it's happening!

> Before 6.x the query is translated into `(title:new OR text:new) AND (title:york OR title:york)...` .

The later versions, the behaviour is

> by default the `query_string` will first apply the analysis on the field `title` and build the query `title:(new OR york OR city)` and then it will combine this query with the `text` field: `title:(new OR york OR city) OR text:(new OR york OR city)` . If you change the `default_operator` to `AND` the query would be: `title:(new AND york AND city) OR text:(new AND york AND city)` . This means that a document will match if it contains `new AND york AND city` in one of the targeted fields.

It's something I need to change in my query term. But I suggest Elastic to let this clearer in the query\_string reference.

> **[Query string query | Elasticsearch Guide \[7.5\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/query-dsl-query-string-query.html)**

---

<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:** [December 16, 2019, 12:38pm UTC](https://discuss.elastic.co/t/query-string-with-operator/208308/3 "2019-12-16T12:38:13Z")

</div>

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