Exclude items from results

Rod0n

I'm using ElasticSearch to search a mongodb with python. I'd like to give the query a list of item ids in order to exclude them from the search results.

I tried with this query but I get no results:

flagged_articles = ["er12", "rt43"]
query = {

    "from": page*limit,
    "size": limit,
    "query": {
        "bool": {
            "must": {
                "range": {
                    "added" : {
                        "from" : "2013-04-11T00:00:00"
                    }
                }
          },
          "ids" : {
            "values" : flagged_articles
          }
    }
ramseykhalaf

It would be faster if you did this with a filter rather than a query. A filter doesn't do any score calculation and so has a lighter overhead.

{
    "filtered" : {
        "query" : {
            "range": {
                "added" : {
                    "from" : "2013-04-11T00:00:00"
                }
            }
        },
        "filter" : {
            "not" : {
                "filter" : {
                    "ids" : {
                        "values" : ["123", "456", "789"]
                    }
                },
                "_cache" : true
            }
        }
    }
}

NOTE: The not filter is not cached by default (the other filters are usually cached). I've added a _cache: true parameter to show you have to cache the not filter if you think you will be using it on subsequent searches.

Good luck!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

GSA how to exclude items with empty metadata from results

From Dev

Does Nautilus exclude any items from its search results?

From Dev

Exclude Hostname from Results

From Dev

Exclude Data from Results

From Dev

Exclude items from a collection in Laravel

From Dev

Exclude items from join table

From Dev

Exclude items from SQL Result

From Dev

Exclude parent vertex from results

From Dev

Exclude certain results from linq

From Dev

angularJs exclude already selected items from array

From Dev

How to exclude from matrix items of a list?

From Dev

SQL - Exclude items from a table with a specific content

From Dev

Exclude items from training set data

From Dev

Exclude ID column from ActiveRecord results

From Dev

How to exclude webstorm files from search results

From Dev

Exclude account from twitter search results

From Dev

Exclude SUM From Results if it Equals 0

From Dev

how to exclude meta data from elasticsearch results?

From Dev

MySQL - exclude all blocked users from the results

From Dev

Group by and exclude minimum and maximum from results

From Dev

Exclude ID column from ActiveRecord results

From Dev

How to Exclude Multiple Values from Search Results

From Dev

Exclude Multiple Values from results in XML data

From Dev

Django exclude Items from Queryset from another Queryset

From Dev

Items Excluded from SQL Results Despite COALESCE

From Dev

Deleting items from javascript array results in error

From Dev

How do you exclude items from AngularJS ng-repeat

From Java

exclude items from array through loop c#

From Dev

How to exclude list of items from Get-ChildItem result in powershell?

Related Related

HotTag

Archive