Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWS OpenSearch with Exclusion List

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading