Senorihl
Senorihl

Reputation: 312

elasticsearch 5 : search with exclude

I try to search on an index for person (by first name and last name) , this part is pretty simple :

GET /my_index/persons/search
{
    "query": {
        "query_string": {
            "query" : "john doe"
        }
    }
}

In addition I want to exclude the person having a specific id, I tried with a filter clause but i wasn't able to properly form the query, can you guys help me ?


EDIT

I've tried

{
    "query":{
        "multi_match":{
            "query":"anne mirande",
            "fields":[
                "first_name",
                "last_name"
            ],
            "type":"cross_fields",
            "operator":"and"
        }
    },
    "filter":{
        "not":{
            "term":{
                "id":1
            }
        }
    }
}

But it throws be this : Unknown key for a START_OBJECT in [filter].

Upvotes: 0

Views: 45

Answers (1)

Hatim Stovewala
Hatim Stovewala

Reputation: 1251

You can use something like this.

GET /my_index/persons/search
{
  "query": {
    "bool": {
      "must": [
        {"term": {
          "name": {
            "value": "john doe"
          }
        }}
      ],
      "must_not": [
        {"term": {
          "_id": {
            "value": "1"
          }
        }}
      ]
    }
  }
}

Upvotes: 1

Related Questions