0

I am trying to get items from my index with empty email.

If i search for items with email:"" i get 0 results

"query": {
    "term": {
      "email": ""
    }
  }
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

if i make a query like:

{
  "query": {
    "term": {
      "id": "1234"
    }
  }
}

i get an item with email:""

"_source" : {
          "id" : "1234",
          "email" : "",
        } 

My mappings look like so:

{
  "mappings": {
    "_doc": {
      "dynamic": "false",
      "properties": {
        "email": {
          "type": "text",
          "analyzer": "email_analyzer"
        },
        "id": {
          "type": "keyword"
        }
      }
    }
  }
}

What can be the cause for this ?

1

2 Answers 2

0

you need use exist query.

{
  "query": {
    "exists": {
      "field": "email"
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can try using this with .keyword like the following

"query": {
"term": {
  "email.keyword": ""
  }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.