Must_not filter not working in query_string


#1

Hi ,
Created index my_index with Created index with ngram analyser

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

{
  "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


 {
        "_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

{
  "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.

 "221": {
            "1": "HFNDL100057"
          }

Thanks


(system) #2

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