# I have two different behaviours with two queries that are exactly the same

**URL:** https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026
**Category:** Elasticsearch
**Created:** [October 26, 2015, 8:56pm UTC](https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026 "2015-10-26T20:56:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ekaitzht](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@ekaitzht](https://discuss.elastic.co/u/ekaitzht)
#### Post date: [October 26, 2015, 8:56pm UTC](https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026/1 "2015-10-26T20:56:38Z")

</div>

I have two different behaviours with two queries that are exactly the same.

In my first query the **must\_not** clause is not filtering **brand3** and **brand4** is returning brand3 and brand4 products. However the second query the must\_not is working. (ES version 1.5.2)

**First query:**

```
GET firstindex/product/_search
{  
            "filter":{
                "bool": {
                    "should": [   
                      {"bool": {
                            "must_not":{ "terms": {"brand.raw": ["brand3,brand4"]}
                            },
                            "must":{
                                "term" : {"retailer" : "retailer1"}    
                            }
                         }
                      }
                    ]
                }    
            }
        
    ,
    "size":10000
}

```

**Second query:**

```
GET secondindex/product/_search
{  
            "filter":{
                "bool": {
                    "should": [   
                       {"bool": {
                            "must_not": { "terms": {"brand.raw": ["brand1,brand2"]}
                            },
                            "must":{
                                "term" : {"retailer" : "retailer2"}    
                            }
                         }
                      }
                    ]
                }    
            }
        
    ,
    "size":10000
}

```

**The mapping for brand is:**

```
 "brand":{
                  "type":"string",
                  "fields":{
                     "raw":{
                        "type":"string",
                        "index":"not_analyzed"
                     }
                  }
               }

```

I got stuck, what I can do to know what is happening? I tried to clear the cache but it's still not working.

Thanks

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [October 27, 2015, 3:13pm UTC](https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026/2 "2015-10-27T15:13:51Z")

</div>

> [@ekaitzht](#):
>
> "terms": {"brand.raw": ["brand3,brand4"]

Without knowing how the documents look like you are searching on, this looks like the terms query syntax might be slightly off here. If you are filtering on `["brand3,brand4"]` on the raw field, this means you will exclude docs that have exactly that string in that field (both brands, including the comma). I'm guessing you might want `["brand3", "brand4"]` instead? Not sure why this makes a difference in your two queries, but the results also depends on your data (after all, the second query is not exactly the same since it has different values in it).

---

<div class="post-metadata">

### Author: ![ekaitzht](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@ekaitzht](https://discuss.elastic.co/u/ekaitzht)
#### Post date: [October 28, 2015, 8:37am UTC](https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026/3 "2015-10-28T08:37:41Z")

</div>

That is the problem that "brand3" and "brand4 is not excluding this data but in the second query it's working and is excluding the data.

I have asked a friend that he controls elasticsearch but he doesn't have any idea. He ask me about the cache, I clear the caceh but it's still not working.Very weird? ☹

---

<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, 11:42pm UTC](https://discuss.elastic.co/t/i-have-two-different-behaviours-with-two-queries-that-are-exactly-the-same/33026/4 "2017-07-05T23:42:12Z")

</div>


