Elasticsearch field is empty (null) records check

In Elasticsearch use and deepening, we often encounter a variety of problems;
Here, the record Elasticsearch field is blank records check;
 
1. Query empty field
When we query a field is empty of data in mysql:
select eid,ent_name from ent_search where enttype_code is NULL;
In elasticsearch, we use the api is exists, this query is: query this field is empty or not this field:
GET ent_search/_search
{
  "_source": ["eid","ent_name"],
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "enttype_code"
                }
            }
        }
    }}
 
2. Query is not an empty field
When we query a field is not empty of data in mysql:
select eid,ent_name from ent_search where enttype_code is NOT NULL;
In elasticsearch, we use the api is exists, this query is:
GET ent_search/_search
{
  "_source": ["eid","ent_name","enttype_code"],
  "query": {
    "constant_score": {
      "filter": {
        "exists": {
          "field": "enttype_code"
        }
      }
    }
  }}
 
### Query Examples
sql_example:
select msg,level  from jsonlog3-2019.06.26 where msg is NULL;
es_explain:
GET /jsonlog3-2019.06.26/_search
{
  "_source": ["msg","level"],
  "query": {
  "bool": {
  "must": [
    {"bool": {"must_not": [
    {"exists": {"field": "msg"}}
      ]}}
      ]
  }
}}
 
sql_example:
select msg,level  from jsonlog3-2019.06.26 where msg is not NULL;
es_explain:
GET /jsonlog3-2019.06.26/_search
{
  "_source": ["msg","level"],
  "query": {
  "bool": {
  "must": [
    {"bool": {"must": [
    {"exists": {"field": "msg"}}
      ]}}
      ]
  }
}}
 
OR
 
GET /qdtech-jsonlog3-2019.06.26/_search
{
  "_source": ["msg","level"],
  "query": {
    "constant_score": {
      "filter": {
        "exists": {
          "field": "msg"
        }
      }
    }
  }
}
 
NOTE: es in the field does not exist and a null field is the same concept;
 

 

Guess you like

Origin www.cnblogs.com/illusioned/p/11915080.html