# MUST\_NOT query not working

**URL:** <https://discuss.elastic.co/t/must-not-query-not-working/198189>\
**Category:** Elasticsearch\
**Created:** [September 5, 2019, 7:47am UTC](https://discuss.elastic.co/t/must-not-query-not-working/198189 "2019-09-05T07:47:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajneesh](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@rajneesh](https://discuss.elastic.co/u/rajneesh)\
**Post date:** [September 5, 2019, 7:47am UTC](https://discuss.elastic.co/t/must-not-query-not-working/198189/1 "2019-09-05T07:47:36Z")

</div>

Hi,  
I have a query in which i want add a must\_not clause to discard all records that have blank data for a particular field. I tried so many ways to do it but none worked. when i issue the same query with few other fields then it works fine.

query:  
{  
"size": 20,  
"\_source": [  
"registrationType1"  
],  
"query": {  
"bool": {  
"must\_not": [  
{  
"term": {  
"registrationType1": ""  
}  
}  
]  
}  
}  
}

the results below still contains registrationType1 with empty values

results return:  
{

- "took": 3,
- "timed\_out": false,
- "\_shards": {
  - "total": 5,
  - "successful": 5,
  - "skipped": 0,
  - "failed": 0},

- "hits": {
  - "total": 100689,
  - "max\_score": 1,
  - "hits": [
    - {
      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3908021",
      - "\_score": 1,
      - "\_source": { }}  
, \* {
      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3837315",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": ""}}  
, \* {

      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3842002",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": "A&R"}}  
, \* {

      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3842033",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": "AMHA"}}  
, \* {

      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3842213",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": "AMHA"}}  
, \* {

      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3842963",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": ""}}  
, \* {

      - "\_index": "oh\_animal",
      - "\_type": "animals",
      - "\_id": "3869063",
      - "\_score": 1,
      - "\_source": {
        - "registrationType1": ""}}

am i missing some mapping configuration ?  
mappings for the field above

"registrationType1": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword"  
}  
}  
}

---

<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:** [October 3, 2019, 7:47am UTC](https://discuss.elastic.co/t/must-not-query-not-working/198189/2 "2019-10-03T07:47:36Z")

</div>

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