MUST_NOT query not working

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

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