# Must\_not filter not working in query\_string

**URL:** <https://discuss.elastic.co/t/must-not-filter-not-working-in-query-string/135012>\
**Category:** Elasticsearch\
**Created:** [June 7, 2018, 2:18pm UTC](https://discuss.elastic.co/t/must-not-filter-not-working-in-query-string/135012 "2018-06-07T14:18:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![veerabhadraiah](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@veerabhadraiah](https://discuss.elastic.co/u/veerabhadraiah)\
**Post date:** [June 7, 2018, 2:18pm UTC](https://discuss.elastic.co/t/must-not-filter-not-working-in-query-string/135012/1 "2018-06-07T14:18:22Z")

</div>

Hi ,  
Created index my\_index with Created index with ngram analyser

```auto
POST my_index

{
            "settings": {
              
                "analysis": {
                  "filter": {
                     "nGram_filter": {
                        "type": "nGram",
                        "min_gram": 3,
                        "max_gram": 3,
                        "token_chars": [
                           "letter",
                           "digit",
                           "punctuation",
                           "symbol",
                           "whitespace"
                        ]
                     }
                  },
                  "analyzer": {
                     "nGram_analyzer": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": [
                           "lowercase",
                           "asciifolding",
                           "nGram_filter"
                        ]
                     }
                  }
               }
            },
            "mappings": {
                "doc": {
                  "dynamic_templates": [
                    {
                      "full_name": {
                        "path_match": "name.*",
                        "mapping": {
                          "type": "text",
                          "term_vector": "yes",
                          "analyzer": "nGram_analyzer",
                          "index": true,
                          "copy_to": "full_name"
                        }
                      }
                    }
                  ]
                }
            }
        }

```

Data looks like

```auto
{
  "took": 23,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 36,
    "max_score": null,
    "hits": [
      {
        "_index": "assetdatalatest",
        "_type": "machineasset",
        "_id": "10",
        "_score": null,
        "_source": {
          "221": {
            "1": "HFNDL100057"
          }
        },
        "sort": [
          "10"
        ]
      },
      {
        "_index": "assetdatalatest",
        "_type": "machineasset",
        "_id": "100",
        "_score": null,
        "_source": {
          "221": {
            "1": "WIN-4NGOFJLKSF1"
          }
        },
        "sort": [
          "100"
        ]
      }
    ]
  }
}

```

Now am applying query MUST\_NOT

```auto

 {
        "_source": [
          "_id","221","357","429"
        ],
   		"from":0,"size":2,
        "sort" : [
           { "_id" : {"order" : "asc"} }
        ],
        "query": {
          "bool": {
            "must_not": [
              {
                  "query_string" : {
                      "query" : "\"*HFNDL100057*\"",
                      "type": "phrase_prefix",
                      "fields" : ["full_221"]
                    }
               }
            ]
          }
        }
   }

```

OUTPUT

```auto
{
  "took": 26,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 36,
    "max_score": null,
    "hits": [
      {
        "_index": "assetdatalatest",
        "_type": "machineasset",
        "_id": "10",
        "_score": null,
        "_source": {
          "221": {
            "1": "HFNDL100057"
          },
          "357": {
            "1": "Windows__20180003"
          },
          "429": {
            "1": "Amber.Bhatnager"
          }
        },
        "sort": [
          "10"
        ]
      },
      {
        "_index": "assetdatalatest",
        "_type": "machineasset",
        "_id": "100",
        "_score": null,
        "_source": {
          "221": {
            "1": "WIN-4NGOFJLKSF1"
          },
          "357": {
            "1": "Windows__20180003"
          },
          "429": {
            "1": "prabhu.singh"
          }
        },
        "sort": [
          "100"
        ]
      }
    ]
  }
}

```

Its giving result with . Must not criteria not working please some one help me.

```auto
 "221": {
            "1": "HFNDL100057"
          }

```

Thanks

---

<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, 2018, 2:18pm UTC](https://discuss.elastic.co/t/must-not-filter-not-working-in-query-string/135012/2 "2018-07-05T14:18:26Z")

</div>

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