Home > Software engineering >  Query to return documents with id not in a list
Query to return documents with id not in a list

Time:09-12

I want to create a query, but I don't want the query to return documents which have already been fetched in a previous query. Here's the JSON

{'query': {'bool': {'filter': [{'term': {'tag': 'name'}},
    {'bool': {'must_not': [{'terms': {'meta.id': list_ids_already_fetched}}]}}]}},
 '_source': {'includes': ['data.subfield']}}

However, it seems that the query returns terms whose meta.id are in list_ids_already_fetched.

CodePudding user response:

Looking your query o tried this:

{
   "query":{
      "bool":{
         "filter":[
            {
               "term":{
                  "tag":"name"
               }
            }
         ],
         "must_not":[
            {
               "terms":{
                  "meta.id":"list_ids_already_fetched"
               }
            }
         ]
      }
   },
   "_source":{
      "includes":[
         "data.subfield"
      ]
   }
}
  • Related