Gerald Hughes
Gerald Hughes

Reputation: 6159

Elasticsearch query must not match text from field

I want to get the results that do not match "statusCode": 200

In order to match text from field you use

GET index01/_search?pretty
{
  "query":{
    "match":{
      "statusCode": 200
    }
  }
}

I tried something like this:

GET ucs_heartbeat/_search?pretty
{
  "query":{
    "match":{
      "statusCode":{
        "query": 200,
        "operator": "must_not"
      }
    }
  }
}

According to: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

Upvotes: 18

Views: 61889

Answers (2)

NeilB
NeilB

Reputation: 357

A possible string query could be:

{
    "query": {
        "query_string": {
            "query": "NOT statusCode: 200"
        }
    },
    "size": 10,
    "from": 0,
    "sort": []
}

Upvotes: 0

Val
Val

Reputation: 217254

Try this instead

GET ucs_heartbeat/_search?pretty
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "statusCode": 200
          }
        }
      ]
    }
  }
}

Upvotes: 37

Related Questions