Home > Blockchain >  AWS OpenSearch with Exclusion List
AWS OpenSearch with Exclusion List

Time:01-04

I'm looking to run an OpenSearch / ElasticSearch query using the Search API. How do I run a search, but exclude specific documents from the results?

For example, I have a movies index containing the names of different movies that are available and you can run a search on the name:

GET /movies/_search
{
  "query": {
    "match": {
      "name": "Night"
    }
  }
}

However, say the user has already indicated that they don't like specific movies, such as "Boogie Nights" and "Aladdin." I'd like to be able to provide a list of movies to exclude in the search. Must I run the search first, and then exclude the items from the results after the fact?

CodePudding user response:

If you know the movies to remove you can to use must_not query with filter query.

  • Related