# How does the \`default\_operator\` of QueryString really work with \`multi field\` in ES 6.1? Does it change the \`OR clause\` between the fields?

**URL:** <https://discuss.elastic.co/t/how-does-the-default-operator-of-querystring-really-work-with-multi-field-in-es-6-1-does-it-change-the-or-clause-between-the-fields/113560>\
**Category:** Elasticsearch\
**Created:** [December 29, 2017, 9:41am UTC](https://discuss.elastic.co/t/how-does-the-default-operator-of-querystring-really-work-with-multi-field-in-es-6-1-does-it-change-the-or-clause-between-the-fields/113560 "2017-12-29T09:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiflu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aiflu/32/26088_2.png) [@aiflu](https://discuss.elastic.co/u/aiflu)\
**Post date:** [December 29, 2017, 9:41am UTC](https://discuss.elastic.co/t/how-does-the-default-operator-of-querystring-really-work-with-multi-field-in-es-6-1-does-it-change-the-or-clause-between-the-fields/113560/1 "2017-12-29T09:41:24Z")

</div>

Hello, I'm updating my project from ES 2.3 to ES 6.1. I feel confused about the algorithm of QueryString with `default_operator` and `fields`.

My purpose is to search in the fields `city.name` and `zipcode.raw` with one query like `New York 10001`. But with the same query, the result is different between 2.3 and 6.1. So I used `_validate API` to debug.

Here's my debug in ES 2.3:

> curl -XGET 'localhost:9200/myindex/\_validate/query?explain&pretty' -d'  
> {  
> "query": {  
> "bool": {  
> "must": [{  
> "query\_string": {  
> "query": "New York 10001",  
> "fields": ["city.name", "zipcode.raw"],  
> "default\_operator": "AND"  
> }  
> }]  
> }  
> }  
> }'

I got the following result (which is what I want , and which is understood according to the doc):

> "explanation" : "filtered(+(+(city.name:new | zipcode.raw:New) +(city.name:york | zipcode.raw:York) +(city.name:10001 | zipcode.raw:10001)))-\>cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@e17eb713)"

Now I use the same query in 6.3:

> curl -XGET 'localhost:19200/buwox-index/\_validate/query?explain=true&pretty' -H 'Content-Type: application/json' -d'  
> {  
> "query": {  
> "bool": {  
> "must": [{  
> "query\_string": {  
> "query": "New York 10001",  
> "fields": ["city.name", "zipcode.raw"],  
> "default\_operator": "AND"  
> }  
> }]  
> }  
> }  
> }'

I got the following result:

> "explanation" : "+(+((+city.name:new +city.name:york +city.name:10001) | zipcode.raw:New York 10001)) #DocValuesFieldExistsQuery [field=\_primary\_term]"

So after several tests, I found that in order to get what I want, I should use the query like this:

> curl -XGET 'localhost:19200/buwox-index/\_validate/query?explain=true&pretty' -H 'Content-Type: application/json' -d'  
> {  
> "query": {  
> "bool": {  
> "must": [{  
> "query\_string": {  
> "query": "New AND York AND 10001",  
> "fields": ["city.name", "zipcode.raw"],  
> "default\_operator": "OR"  
> }  
> }]  
> }  
> }  
> }'

With this query I can get the same result as 2.3:

> "explanation" : "+(+(+(city.name:new | zipcode.raw:New) +(city.name:york | zipcode.raw:York) +(city.name:10001 | zipcode.raw:10001))) #DocValuesFieldExistsQuery [field=\_primary\_term]"

So here comes my question, according to the doc [QueryString](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html), if there is no explicit operator, the query will use what I defined in `default_operator`. Right?  
And with `multi field`, the relation between the fields is `OR clause`.  
So why couldn't I use no explicit operator with `default_operator = AND` to get the purpose? It seems that the `default_operator` changes also the combination between the `multi field`, if I don't use explicit operator.

I don't think it's related to my mapping. But just in case, I post also my mapping in 2.3 and 6.1.

My mapping in 2.3:

> ...  
> "zipcode": {  
> "type": "integer",  
> "index": "not\_analyzed",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> },  
> "city": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> },  
> "slug": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "include\_in\_all": false  
> }  
> }  
> }  
> ...

My mapping in 6.1:

> ...  
> "analysis": {  
> "analyzer": {  
> "default": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": ["asciifolding", "lowercase", "geowords"]  
> }  
> },  
> "filter": {  
> "geowords": {  
> "type" : "word\_delimiter\_graph",  
> "split\_on\_case\_change" : false,  
> "preserve\_original" : false  
> }  
> }  
> }  
> ...  
> "zipcode": {  
> "type": "integer",  
> "index": true,  
> "fields" : { "raw" : { "type" : "keyword", "index" : true } }  
> },  
> "city": {  
> "properties" : {  
> "name" : { "type": "text", "fields" : { "raw" : { "type" : "keyword", "index" : true } } },  
> "slug" : { "type": "keyword", "index": true }  
> }  
> }  
> ...

Can someone help? Thanks.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 29, 2017, 10:02am UTC](https://discuss.elastic.co/t/how-does-the-default-operator-of-querystring-really-work-with-multi-field-in-es-6-1-does-it-change-the-or-clause-between-the-fields/113560/2 "2017-12-29T10:02:05Z")

</div>

Please don't post the same thing more than once 🙂

> [@Has\`default\_operator\` of QueryString changed algorithm with \`multi field\` from ES2.3 to ES6.1?](https://discuss.elastic.co/t/has-default-operator-of-querystring-changed-algorithm-with-multi-field-from-es2-3-to-es6-1/113564):
>
> Hello, I'm updating my project from ES 2.3 to ES 6.1. I feel confused about the algorithm of QueryString with default\_operator and fields. My purpose is to search in the fields city.name and zipcode.raw with one query like New York 10001. But with the same query, the result is different between 2.3 and 6.1. So I used \_validate API to debug. Here's my debug in ES 2.3: GET /myindex/\_validate/query?explain&pretty' -d' { "query": { "bool": { "must": [{ "query\_string": { "query": "N…

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 29, 2017, 10:02am UTC](https://discuss.elastic.co/t/how-does-the-default-operator-of-querystring-really-work-with-multi-field-in-es-6-1-does-it-change-the-or-clause-between-the-fields/113560/3 "2017-12-29T10:02:09Z")

</div>


